結果
| 問題 | No.401 数字の渦巻き |
| コンテスト | |
| ユーザー |
r_ishida
|
| 提出日時 | 2025-12-31 16:30:41 |
| 言語 | Python3 (3.14.2 + numpy 2.4.0 + scipy 1.16.3) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 717 bytes |
| 記録 | |
| コンパイル時間 | 308 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2025-12-31 16:30:44 |
| 合計ジャッジ時間 | 2,410 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
import math
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n = I()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
s = [[0]*n for _ in range(n)]
x, y = 0, 0
d = 0
for i in range(1, n*n+1):
s[y][x] = i
nx = x + dx[d]
ny = y + dy[d]
if 0 <= nx < n and 0 <= ny < n and s[ny][nx] == 0:
x, y = nx, ny
else:
d = (d + 1) % 4
x += dx[d]
y += dy[d]
for row in s:
print(" ".join(map(lambda x: '{0:03}'.format(x), row)))
r_ishida