Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

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

Автор BillyGyde001, история, 2 месяца назад, По-английски

I passed problem C of round 980 (Div 1) with a sketchy code that I wrote: https://mirror.codeforces.com/contest/2023/submission/300471200

The code has a fast and slow pointer. Set an initial value called match to 0. If a[fast%n] != b[slow%n], increase fast by 1, and set match to 0. Otherwise, increase fast and slow both by 1, and increase match by 1. If fast is greater than slow by n, then a is not a cycle of b. Otherwise, if match is n, then a is a cycle of b.

I would really appreciate it if someone could send me either a test case that TLEs this code, or the proof of why this code works. Thanks.

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

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

If my understanding of what you're doing is correct, testcase where the array a is n1 ones and 1 two and b is n ones TLEs, because whenever fast%n reaches the 2 in a, it just increases by 1, increasing fastslow by 1, and then we just traverse the entire array again.