The contest was prepared by awoo, Neon, adedalic, Roms and me. We are very grateful to all of the testers of the contest: PavelKunyavskiy, ashmelev, vladmart, Vladosiya and mariibykova.
We hope you enjoyed both the problems and coding in Kotlin!
Okay, now let's talk about how these problems can be solved:
Idea: BledDest, preparation: Neon
Idea: BledDest, preparation: awoo
Idea: BledDest, preparation: awoo
Idea: BledDest, preparation: Neon
1910F - Build Railway Stations
Idea: BledDest, preparation: awoo
Idea: adedalic, preparation: adedalic
Idea: BledDest, preparation: BledDest
Idea: BledDest, preparation: awoo
Idea: BledDest, preparation: BledDest
Nicely curated problems orz in order of difficulty to slowly dive into the syntax and structure of Kotlin, took me time but enjoyed in solving and learning syntax on way.
For the problem H, there is actually an
O(nlogA)
solution. When i'm saying "b.s.", i'm refering to "binary search". TheO(nlognlogA)
complexity we need to "patch" comes in 2 parts: the sorting, and the b.s.. For the sorting, we can dolsd radix sort
(with base 10), and store every iteration of it. For the second part, we don't actually have to do b.s.. If we focus on the "queries" of the b.s. on an arbitrary array (one of thelogA
ones), the inputs of the b.s. arem-ar[i]
, wherem
is the current power of 10, andar[i]
is the value on the array. Becausear
is sorted (we don't care about order), the sequencem-ar[i]
is also sorted, in reverse order (becausem
is constant). Therefore, we can find all the positions of the sequence, with a basic 2-pointer method (see merge-sort), in linear time. So we haveO(n)
time for every array, and we havelogA
arrays, so the final time (and space) complexity isO(nlogA)
. I'm gonna upload c++ code in a while too.I just coded it up, the only test cases i've tested it on, are the 2 input examples from the problem statement (it works). 239141643 It obviously doesn't compile, its on c++. I sent the submission for you to see the code.
ALSO: The space complexity can be improved to
O(n)
, even tho i'm not gonna bother coding it: We need to store only the current iteration of the (base 10)lsd radix sort
, and calculate the values for the indeces, and then move on to the next iteration. From now on, we don't need the previous one, so we don't have to keep storing it.Final time complexity:
O(nlogA)
, where A is the max elementFinal space complexity:
O(n)
.Just did it, 239202554. I believe that this is the optimal time and space complexity