--oOoOoOoOoOoOo--'s blog

By --oOoOoOoOoOoOo--, history, 4 years ago, In English

1335E2 - Three Blocks Palindrome (hard version)

In this problem, the solution outlined by the editorial is $$$O(n*200*200)$$$, here $$$N$$$ <= $$$200000$$$.

How is the solution able to pass with that time complexity on a constraint like this?

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

You pick a number (for first and third block) and iterate on its positions. Irregardless of the 'number' of numbers, there are only N positions in total to pick, thus the complexity is O(N * 200). Of course you have to implement it in an appropriate way. Similar to how, when you DFS/BFS, you iterate on the children of a node, and you do it for every node! It seems O(N^2) but there are only N distinct nodes to visit in total.