← All problemsSign in

Square Loop

CodeChefRating 3312Open on judge ↗

You are given an $N\times N$ square matrix $G$. Each cell of the matrix contains either `O` or `X `. A movement from cell $(X_1, Y_1)$ to $(X_2, Y_2)$ is *legal* only if: - $G_{(X_1,Y_1)}=G_{(X_2,Y_2)}=$ `O`; - $X_1=X_2$ or $Y_1=Y_2$. A path $(X_1,Y_1)\rightarrow (X_2,Y_2)\rightarrow \dots \rightarrow (X_{K},Y_{K})$ of **length** $K$ is *valid* if it meets **all** of the following conditions: -

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start