結果

問題 No.401 数字の渦巻き
ユーザー gorugo30gorugo30
提出日時 2021-02-23 21:53:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 81,696 KB
実行使用メモリ 53,416 KB
最終ジャッジ日時 2023-10-23 22:52:21
合計ジャッジ時間 3,291 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,416 KB
testcase_01 AC 39 ms
53,416 KB
testcase_02 AC 39 ms
53,416 KB
testcase_03 AC 37 ms
53,416 KB
testcase_04 AC 38 ms
53,416 KB
testcase_05 AC 38 ms
53,416 KB
testcase_06 AC 37 ms
53,416 KB
testcase_07 AC 38 ms
53,416 KB
testcase_08 AC 37 ms
53,416 KB
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 #

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 i 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 = " ")
for i in range(N):
    for j in range(N):
        pr(grid[i][j])
    print("")
0