結果
問題 | No.401 数字の渦巻き |
ユーザー |
|
提出日時 | 2023-01-19 00:02:07 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 505 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-06-11 23:34:41 |
合計ジャッジ時間 | 2,157 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
n = int(input())ANS = [[0 for _ in range(n)] for _ in range(n)]Directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]curr = 1ci, cj = 0, 0didx = 0while True:ANS[ci][cj] = f"{curr:03}"curr += 1if curr > n**2:breakwhile True:di, dj = Directions[didx]ni, nj = ci + di, cj + djif 0 <= ni < n and 0 <= nj < n and ANS[ni][nj] == 0:ci, cj = ni, njbreakdidx = (didx + 1) % 4for i in range(n):print(' '.join(ANS[i]))