From 42afd2db045d75ee2c45d9050e0c3e65cba53582 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 20 Feb 2025 11:23:11 +0900 Subject: [PATCH] =?UTF-8?q?[20250220]=20BOJ=20/=20G4=20/=20=EA=B1=B0?= =?UTF-8?q?=EC=9A=B8=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20 BOJ G4 \352\261\260\354\232\270.md" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "khj20006/202502/20 BOJ G4 \352\261\260\354\232\270.md" diff --git "a/khj20006/202502/20 BOJ G4 \352\261\260\354\232\270.md" "b/khj20006/202502/20 BOJ G4 \352\261\260\354\232\270.md" new file mode 100644 index 00000000..dd0140ea --- /dev/null +++ "b/khj20006/202502/20 BOJ G4 \352\261\260\354\232\270.md" @@ -0,0 +1,40 @@ +```cpp + +#include +#include +using namespace std; + +int A[1002][1002]{}, N, M, ans[4001]{}; +int dx[2] = { -1,0 }; +int dy[2] = { 0,1 }; + +int main() +{ + cin.tie(0)->sync_with_stdio(0); + + cin >> N >> M; + for (int i = 1; i <= N; i++) for (int j = 1; j <= M; j++) cin >> A[i][j]; + + int cnt = 0; + for (int i = 1; i <= N; i++) A[i][0] = ++cnt; + for (int j = 1; j <= M; j++) A[N + 1][j] = ++cnt; + for (int i = N; i >= 1; i--) A[i][M + 1] = ++cnt; + for (int j = M; j >= 1; j--) A[0][j] = ++cnt; + + for (int cur = 1; cur <= N + M; cur++) { + int x = min(N, cur), y = max(1, cur - N), dir = cur <= N; + while (1 <= x && x <= N && 1 <= y && y <= M) { + if (A[x][y]) dir ^= 1; + x += dx[dir], y += dy[dir]; + } + + int from = cur, to = A[x][y]; + ans[from] = to; + ans[to] = from; + } + + for (int i = 1; i <= cnt; i++) cout << ans[i] << ' '; + +} + +```