結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-16 12:19:58 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 611 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-11-30 08:04:14 |
| 合計ジャッジ時間 | 2,337 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
n = int(input())
m = list()
for i in range(n):
m.append([0]*n)
d = 0
i = 0
j = 0
for v in range(1,n*n+1):
m[i][j] = str(v).zfill(3)
if d % 4 == 0 and not (j+1 < n and m[i][j+1] == 0):
d += 1
elif d % 4 == 1 and not (i+1 < n and m[i+1][j] == 0):
d += 1
elif d % 4 == 2 and not (j-1 >= 0 and m[i][j-1] == 0):
d += 1
elif d % 4 == 3 and not (i-1 >= 0 and m[i-1][j] == 0):
d += 1
if d % 4 == 0:
j+=1
elif d %4 == 1:
i+=1
elif d %4 == 2:
j-=1
elif d %4 == 3:
i-=1
for i in range(n):
print(' '.join(m[i]))