Блог пользователя brain-0-dead

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

Prob: 88B - Keyboard

sample submission: 110834753,

What am I doing wrong here? I keep getting tle on test case 51.

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

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

The worst time complexity of your solution is O(q(nm)^2), and with given constraints it is bound to give TLE on some large test case. Rather then finding the closest shift and alphabet pair every time you encounter one, you should do this just once for each alphabet and store the result for later use. In this way your time complexity will reduce to O(q+26(nm)^2).