Блог пользователя --oOoOoOoOoOoOo--

Автор --oOoOoOoOoOoOo--, история, 4 года назад, По-английски

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?

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

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.