結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
|
提出日時 | 2018-02-23 00:51:44 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 610 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-10-04 12:34:02 |
合計ジャッジ時間 | 2,278 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
from collections import deque def main(): N = int(input()) dir = deque([(0, 1), (1, 0), (0, -1), (-1, 0)]) grid = [[0 for _ in [0] * N] for _ in [0] * N] grid[0][0] = '001' x, y = 0, 0 n = 2 while n <= N * N: i, j = dir[0] if all((0 <= x + i < N, 0 <= y + j < N)): if grid[x+i][y+j] == 0: grid[x+i][y+j] = str(n).zfill(3) x += i y += j n += 1 else: dir.rotate(-1) else: dir.rotate(-1) for n in grid: print(*n, sep=' ') main()