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

Автор phyzzmat, история, 5 лет назад, По-английски

Hello everyone. Previously I was more of a Python programmer, but now I am trying to expand my knowledge of C++, so I am solving tasks in it more and more frequently. Today I experienced a strange issue with task 1194C - From S To T.

The solution — 57031662 — I wrote returned WA2, and no minor changes seemed to alleviate the problem (which cost me a lot of time). After 20 unsuccessful minutes of trying to zero in on the bug, I just coded the same thing in Python — 57047262 — and it AC'd flawlessly.

The specific test case I am getting an error on is the following:

acefhjlnprtvxz abcdedfghijklmnopqrstuvwxyzabcdedfghijklmnopqrstuvwxyz abcdedfghijklmnopqrstuvwxyzabcdedfghijklmnopqrstuvwxyz

"YES" is expected, whereas the program outputs "NO". However, the C++ submission answers this test case correctly when run locally, while giving another output on Codeforces.

Could you please help me locate the problem? P.S. We are all human and prone to making mistakes, so I am not excluding the possibility that I missed something very obviously wrong.

upd: Thanks. Problem solved. I was extremely stupid to miss such a thing. Fun thing: actually, test case 28 ran correctly on CF. It was simply a redundant "no" from test 27 which messed up the order of answers, therefore I started thinking that the issue is more complex than it is.

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

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

Auto comment: topic has been updated by phyzzmat (previous revision, new revision, compare).

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
if (chp[i] > ch[i])

in this condition your code can print NO multiple times for the same query

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

Auto comment: topic has been updated by phyzzmat (previous revision, new revision, compare).

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

You forgot to break if condition once you print "NO". Everything else is correct .