結果

問題 No.2673 A present from B
ユーザー Today03Today03
提出日時 2024-03-16 04:49:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-03-16 04:49:16
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
9,984 KB
testcase_01 AC 32 ms
9,984 KB
testcase_02 AC 31 ms
9,984 KB
testcase_03 AC 32 ms
9,984 KB
testcase_04 AC 31 ms
9,984 KB
testcase_05 AC 31 ms
9,984 KB
testcase_06 AC 462 ms
12,288 KB
testcase_07 AC 406 ms
12,288 KB
testcase_08 AC 415 ms
12,288 KB
testcase_09 AC 33 ms
9,984 KB
testcase_10 AC 33 ms
9,984 KB
testcase_11 AC 33 ms
9,984 KB
testcase_12 AC 134 ms
10,624 KB
testcase_13 AC 131 ms
10,496 KB
testcase_14 AC 216 ms
11,008 KB
testcase_15 AC 88 ms
10,240 KB
testcase_16 AC 90 ms
10,240 KB
testcase_17 AC 68 ms
10,112 KB
testcase_18 AC 97 ms
10,368 KB
testcase_19 AC 34 ms
9,984 KB
testcase_20 AC 180 ms
10,880 KB
testcase_21 AC 330 ms
11,776 KB
testcase_22 AC 33 ms
9,984 KB
testcase_23 AC 33 ms
9,984 KB
testcase_24 AC 32 ms
9,984 KB
testcase_25 AC 33 ms
9,984 KB
testcase_26 AC 33 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [a - 1 for a in A]

dp = [[1e9] * N for _ in range(M + 1)]

for i in range(N):
    dp[M][i] = i

for i in reversed(range(M)):
    for j in range(N):
        if j == A[i]:
            dp[i][j] = dp[i + 1][j + 1]
        elif j == A[i] + 1:
            dp[i][j] = dp[i + 1][j - 1]
        else:
            dp[i][j] = dp[i + 1][j]
    for j in range(N - 1):
        dp[i][j] = min(dp[i][j], dp[i][j + 1] + 1)
        dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1)

print(*dp[0][1:])
0