結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
|
提出日時 | 2021-02-23 21:55:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 492 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 60,172 KB |
最終ジャッジ日時 | 2024-09-22 16:11:03 |
合計ジャッジ時間 | 2,446 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
N = int(input()) dr = [0, 1, 0, -1] dc = [1, 0, -1, 0] r = 0 c = 0 d = 0 i = 1 grid = [[-1] * N for j in range(N)] while i <= N * N: grid[r][c] = i i += 1 nr = r + dr[d] nc = c + dc[d] if 0 <= nr < N and 0 <= nc < N and grid[nr][nc] == -1: r = nr c = nc else: d = (d + 1) % 4 r = r + dr[d] c = c + dc[d] def pr(x): if x < 10: print("00" + str(x), end = " ") elif x < 100: print("0" + str(x), end = " ") else: print(x, end = " ") for i in range(N): for j in range(N): pr(grid[i][j]) print("")