結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2018-05-28 22:02:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 396 bytes |
コンパイル時間 | 83 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-06-30 07:52:55 |
合計ジャッジ時間 | 2,069 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
from itertools import cycle N = int(input()) a = [[1]*(N+2)] + [[1]+[0]*N+[1] for _ in [0]*N] + [[1]*(N+2)] direction = cycle(((1, 0), (0, 1), (-1, 0), (0, -1))) x, y, dirx, diry = 1, 1, 0, 0 for i in range(1, N**2+1): if a[y+diry][x+dirx] != 0: dirx, diry = next(direction) x, y = x+dirx, y+diry a[y][x] = "{:03d}".format(i) for l in a[1:-1]: print(" ".join(l[1:-1]))