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

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

Can anyone explain to me why I am getting TLE in this problem:- https://codeforces.me/contest/1526/problem/D. Here is my submission:- https://codeforces.me/contest/1526/submission/117731679. I just iterated over all the 24 permutations of "ANOT" and then formed the string and found the minimum swaps required for this string in O(n).(the counting part is taken from GFG which works in O(n)).

Thank you.

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

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

Your result checking function is too slow. It is at least O(result) as you're incrementing the result by one. And this is O(N^2) for some cases.