結果

問題 No.401 数字の渦巻き
ユーザー bellangeldindonbellangeldindon
提出日時 2019-05-14 13:16:15
言語 Python2
(2.7.18)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 6,700 KB
実行使用メモリ 6,060 KB
最終ジャッジ日時 2023-09-25 13:45:29
合計ジャッジ時間 1,903 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,944 KB
testcase_01 AC 12 ms
6,044 KB
testcase_02 AC 12 ms
5,860 KB
testcase_03 AC 11 ms
5,896 KB
testcase_04 AC 11 ms
5,904 KB
testcase_05 AC 11 ms
5,868 KB
testcase_06 AC 11 ms
6,060 KB
testcase_07 AC 11 ms
5,848 KB
testcase_08 AC 12 ms
5,988 KB
testcase_09 AC 11 ms
5,844 KB
testcase_10 AC 12 ms
5,896 KB
testcase_11 AC 11 ms
6,012 KB
testcase_12 AC 12 ms
6,016 KB
testcase_13 AC 12 ms
5,896 KB
testcase_14 AC 11 ms
6,052 KB
testcase_15 AC 12 ms
6,000 KB
testcase_16 AC 11 ms
5,872 KB
testcase_17 AC 12 ms
5,896 KB
testcase_18 AC 12 ms
5,872 KB
testcase_19 AC 12 ms
6,036 KB
testcase_20 AC 12 ms
5,920 KB
testcase_21 AC 12 ms
5,848 KB
testcase_22 AC 12 ms
5,836 KB
testcase_23 AC 12 ms
5,924 KB
testcase_24 AC 13 ms
5,964 KB
testcase_25 AC 12 ms
5,836 KB
testcase_26 AC 12 ms
5,984 KB
testcase_27 AC 12 ms
5,892 KB
testcase_28 AC 13 ms
5,916 KB
testcase_29 AC 13 ms
6,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

move = [[0, 1], [1, 0], [0, -1], [-1, 0]]
N = int(raw_input())
board = []
for i in range(0, N):
	lst = []
	for j in range(0, N):
		lst.append(0)
	board.append(lst)
now = [0, 0]
index = 1
flag = 0
while index <= N*N:
	board[now[0]][now[1]] = index
	nextx = now[0]+move[flag][0]
	nexty = now[1]+move[flag][1]
	if nextx<0 or N-1<nextx or nexty<0 or N-1<nexty or board[nextx][nexty] != 0:
		flag = (flag+1)%4
		nextx = now[0]+move[flag][0]
		nexty = now[1]+move[flag][1]
	now = [nextx, nexty]
	index += 1

for i in range(0, N):
	s = ''
	for j in range(0, N):
		if len(str(board[i][j])) == 1: s = s + '00'
		elif len(str(board[i][j])) == 2: s = s + '0'
		s = s + str(board[i][j])
		if j != N-1: s = s + ' '
	print s
0