Anyone mind telling me what was wrong in my submission (the actual code starts from line 200) for Optimal Memory Address.
The idea was to building a weighted trie on the prime factorization of the numbers and finding the node that minimizes the sum of distances to all the marked special nodes.
Edit: I found a few errors, the main one was when traversing the node to minimize distance I was incrementing by the number of all elements in parentās subtree rather than the total number of elements, it still TLEs in one testcase but I should be able to figure that out.
I believe that your solution (as well as the solution of mrho) are actually unintended and run in quadratic on an edge case, which you barely passed through constant factor tricks. Note that the Java submission of uwi runs in 0.24 seconds.
I also passed with O((n*2^k+e)*log(n*2^k)) but I think this theoretical complexity isnāt actually achievable. I cant think of a case where all bitmasks are actually traversed + are all āvaluableā (since we just break out of dijkstra once we find the first path).
The intended solution was to compress the graph to just keys and locked nodes using O(K) Dijkstra, and then to run the subtask 2 solution on that graph. I think that the theoretical complexity is achievable (consider all keys connected to each other and connected to the node 1) but unfortunately did not have a specific test case. It seems that most people who tried n*2^k failed subtask 3, regardless.
I apologise, it seems that your solution doesnāt encounter the O(N^2) blowup that I thought it did. (I guess mrhoās solution would also be same?) Unfortunately, I donāt think I have the permissions to check the cerr from the file. Testing it locally finds that it is pretty much O(N).
Apologies for the tight TL. Solutions of testers and setter were double as fast because they used map with key as int, I believe (which also led to the possibility of O(N^2) blowup). Congrats on all AC in contest, though.
P.S. i have put asserts in the code at every place after i take input assert(y!=-1). but i am not getting runtime error which means all my asserts are passing. but still i am getting WA.