結果

問題 No.401 数字の渦巻き
ユーザー utsumidaisukeutsumidaisuke
提出日時 2018-12-21 10:41:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 11,800 KB
実行使用メモリ 10,436 KB
最終ジャッジ日時 2023-10-26 01:17:06
合計ジャッジ時間 2,656 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,228 KB
testcase_01 AC 27 ms
10,228 KB
testcase_02 AC 28 ms
10,228 KB
testcase_03 AC 27 ms
10,232 KB
testcase_04 AC 27 ms
10,232 KB
testcase_05 AC 27 ms
10,236 KB
testcase_06 AC 26 ms
10,236 KB
testcase_07 AC 27 ms
10,240 KB
testcase_08 AC 27 ms
10,244 KB
testcase_09 AC 26 ms
10,252 KB
testcase_10 AC 28 ms
10,256 KB
testcase_11 AC 27 ms
10,260 KB
testcase_12 AC 27 ms
10,264 KB
testcase_13 AC 30 ms
10,268 KB
testcase_14 AC 28 ms
10,276 KB
testcase_15 AC 29 ms
10,284 KB
testcase_16 AC 30 ms
10,292 KB
testcase_17 AC 30 ms
10,300 KB
testcase_18 AC 30 ms
10,308 KB
testcase_19 AC 31 ms
10,316 KB
testcase_20 AC 31 ms
10,320 KB
testcase_21 AC 31 ms
10,332 KB
testcase_22 AC 32 ms
10,340 KB
testcase_23 AC 34 ms
10,348 KB
testcase_24 AC 37 ms
10,360 KB
testcase_25 AC 37 ms
10,376 KB
testcase_26 AC 38 ms
10,388 KB
testcase_27 AC 40 ms
10,404 KB
testcase_28 AC 41 ms
10,424 KB
testcase_29 AC 42 ms
10,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

ls = []
for i in range(n):
    for j in range(n):
        ls.append([i,j])
ls.remove([0,0])

a = [[0,1], [1,0], [0,-1], [-1,0]]
ps = [0,0]
ts = [0,0]
sq = [[0,0]]
ap = 0
while len(ls) > 0:
    ts[0] = ps[0]+a[ap%4][0]
    ts[1] = ps[1]+a[ap%4][1]
    if ts in ls:
        ps = ts.copy()
        sq.append(ps)
        ls.remove(ps)
    else:
        ap += 1
        ts[0] = ps[0]+a[ap%4][0]
        ts[1] = ps[1]+a[ap%4][1]
        ps = ts.copy()
        sq.append(ps)
        ls.remove(ps)

tmp=[]
for i in range(n):
    tmp.append([])
    for j in range(n):
        tmp[i].append([])

numb = [str(i+1).zfill(3) for i in range(n**2)]

for i,j in zip(sq,numb):
    tmp[i[0]][i[1]] = j

for i in range(n):
    print(" ".join(tmp[i]))
0