結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
![]() |
提出日時 | 2021-12-28 21:09:49 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 667 bytes |
コンパイル時間 | 2,048 ms |
コンパイル使用メモリ | 206,596 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 13:57:16 |
合計ジャッジ時間 | 3,094 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
import std; void main() { int N; readf("%d\n", N); auto A = new int[][](N, N); int x, y, num, dir; while (num < N * N) { A[x][y] = ++num; if (dir == 0 && (y >= N - 1 || A[x][y+1] > 0)) dir = 1; else if (dir == 1 && (x >= N - 1 || A[x+1][y] > 0)) dir = 2; else if (dir == 2 && (y <= 0 || A[x][y-1] > 0)) dir = 3; else if (dir == 3 && (x <= 0 || A[x-1][y] > 0)) dir = 0; int d = dir < 2 ? 1 : -1; (dir & 1 ? x : y) += d; } foreach (i; 0 .. N) { foreach (j; 0 .. N) { format("%03d", A[i][j]).write; write(j == N - 1 ? "\n" : " "); } } }