結果

問題 No.401 数字の渦巻き
ユーザー _KingdomOfMoray_KingdomOfMoray
提出日時 2019-11-25 21:37:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,167 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-22 16:17:08
合計ジャッジ時間 2,067 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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 % m == 0:
        print()
    print(res[i] + ' ', end='')
0