SafetyKitOA #2
Robot Circle Existence (Infinite Loop Boundedness)
Estimated MediumJudge-ready
Topics (AI-labelled)SimulationBits & Math
A command string made of G (move forward), L, and R (turn in place) is executed repeatedly; determine whether the robot's path is bounded.
Input
The first line contains q (1≤q≤1000), followed by q lines of command strings of length 1..10000 consisting only of the characters G/L/R.
Output
For each string, output YES (bounded) or NO (unbounded).
Example 1
Input:
3
G
GL
RGRG
Output:
NO
YES
YES
Example notes
Derive a linear scan/dynamic programming solution directly from the problem rules; the examples have been checked one by one against an independently built oracle.
Editorial
Loading solution…