[Thread] B
# codeforces
a
[Thread] B
s
@SerVB here's my B. It looks very similar to your but times out. Can you spot the difference? https://codeforces.com/contest/1170/submission/54764006 Is removing first element really that expensive?
s
need to use a collection w/ effective first and last elements access
s
list is not such a collection?
(specifically, arraylist)
s
no. it's like a vector or dinamically sized array. the correct choice here is LinkedList or Queue or something else...
s
interesting...
ah, the copies on remove
s
oh, I've written about D... sorry...
s
I think the same issue was my problem for B though
I dropped elements from a long array list
rather than tracking an index
s
yeah, I see
visits.removeAt(0)
s
it's a shame the practice problems didn't punish this behavior, I could have learned from them!
next time I will know 🙂
p
Yea, you could just use usual
for
loop.
b
did anyone used memoization on this? I could not participate in this contest 😕
p
You can participate (submit solutions) even after contest is over.
b
nice, I'll try later