結果

問題 No.401 数字の渦巻き
ユーザー tookunn_1213
提出日時 2016-07-23 00:07:11
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-11-06 09:56:06
合計ジャッジ時間 2,004 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
s = [['' for j in range(N)]for i in range(N)]
used = [[False for j in range(N)] for i in range(N)]
dy = [0,1,0,-1]
dx = [1,0,-1,0]
q = [[0,0]]
it,k = 0,1
while len(q) > 0:
	p = q.pop(0)
	used[p[0]][p[1]] = True
	s[p[0]][p[1]] = '%03d' % k
	k += 1
	ny = p[0] + dy[it]
	nx = p[1] + dx[it]
	if ny < 0 or ny >= N or nx < 0 or nx >= N or used[ny][nx]:
		it = (it + 1) % 4
		ny = p[0] + dy[it]
		nx = p[1] + dx[it]
	if ny < 0 or ny >= N or nx < 0 or nx >= N or used[ny][nx]:
		break
	if not used[ny][nx]:
			q.append([ny,nx])
for i in range(N):
	print(' '.join(s[i]))
0