結果

問題 No.401 数字の渦巻き
ユーザー _KingdomOfMoray_KingdomOfMoray
提出日時 2019-11-25 21:46:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 8,464 KB
最終ジャッジ日時 2023-08-04 18:24:58
合計ジャッジ時間 1,896 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,160 KB
testcase_01 AC 16 ms
8,156 KB
testcase_02 AC 16 ms
8,300 KB
testcase_03 AC 15 ms
8,192 KB
testcase_04 AC 15 ms
8,160 KB
testcase_05 AC 15 ms
8,188 KB
testcase_06 AC 15 ms
8,192 KB
testcase_07 AC 16 ms
8,164 KB
testcase_08 AC 16 ms
8,304 KB
testcase_09 AC 15 ms
8,324 KB
testcase_10 AC 15 ms
8,220 KB
testcase_11 AC 15 ms
8,328 KB
testcase_12 AC 16 ms
8,244 KB
testcase_13 AC 15 ms
8,336 KB
testcase_14 AC 15 ms
8,208 KB
testcase_15 AC 15 ms
8,328 KB
testcase_16 AC 16 ms
8,224 KB
testcase_17 AC 16 ms
8,328 KB
testcase_18 AC 16 ms
8,232 KB
testcase_19 AC 16 ms
8,344 KB
testcase_20 AC 16 ms
8,292 KB
testcase_21 AC 15 ms
8,268 KB
testcase_22 AC 16 ms
8,284 KB
testcase_23 AC 16 ms
8,380 KB
testcase_24 AC 16 ms
8,292 KB
testcase_25 AC 16 ms
8,196 KB
testcase_26 AC 17 ms
8,256 KB
testcase_27 AC 17 ms
8,172 KB
testcase_28 AC 17 ms
8,156 KB
testcase_29 AC 17 ms
8,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

m = int(input())
n = m * m
a = [[0] * m for i in range(m)]

cur = 1
yoko = m
tate = m
x = 0
y = 0
while True:
    # 左から右
    for i in range(yoko):
        a[y][x] = cur
        x += 1
        cur += 1
    tate -= 1
    x -= 1
    y += 1

    if cur == n+1:
        break
    # 上から下
    for i in range(tate):
        a[y][x] = cur
        y += 1
        cur += 1
    yoko -= 1
    y -= 1
    x -= 1 

    if cur == n+1:
        break
    # 右から左
    for i in range(yoko):
        a[y][x] = cur
        x -= 1
        cur += 1
    tate -= 1
    x += 1
    y -= 1

    if cur == n+1:
        break
    # 下から上
    for i in range(tate):
        a[y][x] = cur
        y -= 1
        cur += 1
    yoko -= 1
    y += 1
    x += 1

    if cur == n+1:
        break

res = []
for i in range(m):
    for j in range(m):
        str_number = str(a[i][j])
        if len(str_number) == 1:
            res.append('00' + str_number)
        elif len(str_number) == 2:
            res.append('0' + str_number)
        else:
            res.append(str_number)
        
for i in range(n):
    if i != 0 and i % m == 0:
        print()
    if i % m == m-1:
        print(res[i], end='')
    else:
        print(res[i] + ' ', end='')
0