← All problemsSign in

(CH) Bear and Sorted Rows

CodeChefRating 3714Open on judge ↗

Limak has a grid that consists of N rows and N columns. He randomly wrote all numbers 1 through N2 in the cells of the grid, one number in each cell. You can assume that each of (N2)! ways was equally likely. Limak asks you to rearrange the numbers in the grid, so that each row will be sorted either increasingly or decreasingly. Scoring Let (r, c) denote the cell at the intersection of the

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