結果

問題 No.401 数字の渦巻き
ユーザー konabekonabe
提出日時 2018-08-01 17:40:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 11,944 KB
実行使用メモリ 10,328 KB
最終ジャッジ日時 2023-10-19 20:44:20
合計ジャッジ時間 1,930 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,232 KB
testcase_01 AC 30 ms
10,232 KB
testcase_02 AC 29 ms
10,232 KB
testcase_03 AC 32 ms
10,232 KB
testcase_04 AC 32 ms
10,232 KB
testcase_05 AC 32 ms
10,232 KB
testcase_06 AC 30 ms
10,236 KB
testcase_07 AC 29 ms
10,236 KB
testcase_08 AC 30 ms
10,240 KB
testcase_09 AC 30 ms
10,240 KB
testcase_10 AC 30 ms
10,244 KB
testcase_11 AC 29 ms
10,244 KB
testcase_12 AC 30 ms
10,244 KB
testcase_13 AC 30 ms
10,248 KB
testcase_14 AC 30 ms
10,248 KB
testcase_15 AC 29 ms
10,252 KB
testcase_16 AC 30 ms
10,252 KB
testcase_17 AC 30 ms
10,256 KB
testcase_18 AC 30 ms
10,260 KB
testcase_19 AC 30 ms
10,264 KB
testcase_20 AC 30 ms
10,268 KB
testcase_21 AC 31 ms
10,280 KB
testcase_22 AC 30 ms
10,284 KB
testcase_23 AC 31 ms
10,288 KB
testcase_24 AC 31 ms
10,292 KB
testcase_25 AC 31 ms
10,300 KB
testcase_26 AC 31 ms
10,304 KB
testcase_27 AC 31 ms
10,312 KB
testcase_28 AC 30 ms
10,316 KB
testcase_29 AC 31 ms
10,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
maps = [[0 for i in range(N)] for j in range(N)]

i, j = 0, 0
n = 1
direct = 0  # 0->, 1down, 2<-, 3up
direct_changed = False
while n < N*N:
    maps[i][j] = n
    direct_changed = False
    if direct == 0:
        if j < N - 1 and maps[i][j+1] == 0:
            j += 1
        else:
            direct = 1
            direct_changed = True
    elif direct == 1:
        if i < N - 1 and maps[i+1][j] == 0:
            i += 1
        else:
            direct = 2
            direct_changed = True
    elif direct == 2:
        if j > 0 and maps[i][j-1] == 0:
            j -= 1
        else:
            direct = 3
            direct_changed = True
    elif direct == 3:
        if i > 0 and maps[i-1][j] == 0:
            i -= 1
        else:
            direct = 0
            direct_changed = True
    if not direct_changed:
        n += 1
        
maps[i][j] = N*N
for i in range(N):
    for j in range(N):
        print("%03d" % maps[i][j], end=" ")
    print()
0