結果

問題 No.401 数字の渦巻き
ユーザー ohanaohana
提出日時 2023-10-20 14:06:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 61,188 KB
最終ジャッジ日時 2023-10-20 14:06:52
合計ジャッジ時間 2,862 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

n = int(input())

A = [[0 for i in range(n)] for j in range(n)]
A[0][0] = 1
f = True
h = ((0, 1), (-1, 0), (0, -1), (1, 0))
c = 0
i, j = 0, 0
while A[i][j] < n**2:
    while (
        0 <= (ii := i + h[c % 4][0]) < n
        and 0 <= (jj := j + h[c % 4][1]) < n
        and A[ii][jj] == 0
    ):
        A[i + h[c % 4][0]][j + h[c % 4][1]] = A[i][j] + 1
        i, j = i + h[c % 4][0], j + h[c % 4][1]
    c += 1

for a in A:
    print(*map(lambda x: "0" * (3 - len(str(x))) + str(x), a))
0