this post was submitted on 16 Dec 2024
12 points (100.0% liked)
NotAwfulTech
386 readers
5 users here now
a community for posting cool tech news you don’t want to sneer at
non-awfulness of tech is not required or else we wouldn’t have any posts
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Day 19! (the cuervo gold....)
disc and code
Ok so my path to this answer was circuitous and I now hate myself a little.P1: Ok, a repeated dfs on suffixes. that shouldn't be too hard. (it was not hard)
P2: Ok, a repeated dfs is a little too slow for me, I wonder how I can speed it up?
forgets about memoisation, a thing that you can do to speed this sort of thing up
I guess the problem is I'm doing an O(mn) match (where m is the number of towels, n is the max towel length) when I can do O(n). I'll build a prefix tree!
one prefix tree later
Ok that still seems to be quite slow. What am I doing wrong?
remembers that memoisation exists
Oh I just need to memoise my dp from part 1. Oops.
Anyway posting the code because I shrunk it down to like two semicolons worth of lines.
(