結果

問題 No.401 数字の渦巻き
ユーザー gorugo30gorugo30
提出日時 2021-02-23 21:55:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 81,516 KB
実行使用メモリ 58,996 KB
最終ジャッジ日時 2023-10-23 22:57:11
合計ジャッジ時間 4,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,428 KB
testcase_01 AC 37 ms
53,428 KB
testcase_02 AC 37 ms
53,428 KB
testcase_03 AC 38 ms
53,428 KB
testcase_04 AC 38 ms
53,428 KB
testcase_05 AC 38 ms
53,428 KB
testcase_06 AC 38 ms
53,428 KB
testcase_07 AC 37 ms
53,428 KB
testcase_08 AC 38 ms
53,428 KB
testcase_09 AC 38 ms
53,428 KB
testcase_10 AC 39 ms
53,428 KB
testcase_11 AC 39 ms
53,428 KB
testcase_12 AC 38 ms
53,428 KB
testcase_13 AC 39 ms
53,428 KB
testcase_14 AC 39 ms
53,428 KB
testcase_15 AC 39 ms
53,428 KB
testcase_16 AC 40 ms
53,428 KB
testcase_17 AC 40 ms
53,428 KB
testcase_18 AC 40 ms
53,428 KB
testcase_19 AC 40 ms
53,428 KB
testcase_20 AC 41 ms
53,428 KB
testcase_21 AC 41 ms
53,428 KB
testcase_22 AC 41 ms
53,428 KB
testcase_23 AC 42 ms
53,428 KB
testcase_24 AC 43 ms
53,428 KB
testcase_25 AC 43 ms
53,428 KB
testcase_26 AC 43 ms
55,476 KB
testcase_27 AC 45 ms
58,996 KB
testcase_28 AC 46 ms
58,996 KB
testcase_29 AC 47 ms
58,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
dr = [0, 1, 0, -1]
dc = [1, 0, -1, 0]
r = 0
c = 0
d = 0
i = 1
grid = [[-1] * N for j in range(N)]
while i <= N * N:
    grid[r][c] = i
    i += 1
    nr = r + dr[d]
    nc = c + dc[d]
    if 0 <= nr < N and 0 <= nc < N and grid[nr][nc] == -1:
        r = nr
        c = nc
    else:
        d = (d + 1) % 4
        r = r + dr[d]
        c = c + dc[d]

def pr(x):
    if x < 10:
        print("00" + str(x), end = " ")
    elif x < 100:
        print("0" + str(x), end = " ")
    else:
        print(x, end = " ")
for i in range(N):
    for j in range(N):
        pr(grid[i][j])
    print("")
0