#DSU0000087. Đường đi của các viên bi (Jeopardy of Dropped Balls)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đường đi của các viên bi (Jeopardy of Dropped Balls)
Jeopardy of Dropped Balls
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Consider an by grid. Each cell contains a direction : means right, means down, and means left.
Drop balls one after another. Ball starts in the first row at column . Each ball follows the direction of its current cell. Immediately after leaving a cell, that cell's direction changes permanently to (down), affecting subsequent balls. A ball finishes after leaving the grid through the bottom.
The first column never points left and the last column never points right, so balls cannot leave through the sides. Report the column where each ball leaves the grid, taking all previous direction changes into account.
Input
The first line contains . The next lines contain direction values each. The last line contains .
Output
Print the exit column of each of the balls in drop order.
Subtasks
- Subtask 1 (20 points): , , , , , .
- Subtask 2 (30 points): , , , , , .
- Subtask 3 (50 points): , , , , , .
Example
Input
5 5 3
1 2 3 3 3
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
1 2 1
Output
2 2 1
Explanation
The first ball changes directions along its route and leaves at column . The next two balls leave at columns and .