Skip to content

Commit 3a4db2d

Browse files
authored
Merge pull request #152 from AlgorithmWithGod/khj20006
[20250220] BOJ / G4 / 거울 / 권혁준
2 parents 1ace857 + 42afd2d commit 3a4db2d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```cpp
2+
3+
#include <iostream>
4+
#include <algorithm>
5+
using namespace std;
6+
7+
int A[1002][1002]{}, N, M, ans[4001]{};
8+
int dx[2] = { -1,0 };
9+
int dy[2] = { 0,1 };
10+
11+
int main()
12+
{
13+
cin.tie(0)->sync_with_stdio(0);
14+
15+
cin >> N >> M;
16+
for (int i = 1; i <= N; i++) for (int j = 1; j <= M; j++) cin >> A[i][j];
17+
18+
int cnt = 0;
19+
for (int i = 1; i <= N; i++) A[i][0] = ++cnt;
20+
for (int j = 1; j <= M; j++) A[N + 1][j] = ++cnt;
21+
for (int i = N; i >= 1; i--) A[i][M + 1] = ++cnt;
22+
for (int j = M; j >= 1; j--) A[0][j] = ++cnt;
23+
24+
for (int cur = 1; cur <= N + M; cur++) {
25+
int x = min(N, cur), y = max(1, cur - N), dir = cur <= N;
26+
while (1 <= x && x <= N && 1 <= y && y <= M) {
27+
if (A[x][y]) dir ^= 1;
28+
x += dx[dir], y += dy[dir];
29+
}
30+
31+
int from = cur, to = A[x][y];
32+
ans[from] = to;
33+
ans[to] = from;
34+
}
35+
36+
for (int i = 1; i <= cnt; i++) cout << ans[i] << ' ';
37+
38+
}
39+
40+
```

0 commit comments

Comments
 (0)