pranjalkhatri950's blog

By pranjalkhatri950, history, 3 weeks ago, In English

Hi codeforces :)

I hope you're doing well! I'm currently working on a problem from Codeforces, and I'm facing some issues with my solution.

Problem Statement can be found here I was doing USACO silver when i encountered it.

My solution simply implements Floyd's cycle detection, where i use 0,1 as slow and fast pointer respectively and when the meet i use the remaining people (2,3,4,5,6,7,8,9) as the slow pointer and (0,1) as fast pointer. This should have queries less than 3(t+c) (I have calculated that). However this produces TLE on test case 80 (however the error shows query limit exceeded). When i compare it with the USACO solution it produces same output which runs fine.

MY solution

USACO solution , submission

I’m hoping someone from the Codeforces community can provide insights or suggestions on how to optimize this solution. Any advice on handling time complexity or debugging the interaction would be really helpful. Thank you in advance!

Looking forward to your suggestions!

Best regards, PK

Full text and comments »