結果

問題 No.2673 A present from B
ユーザー nikoro256nikoro256
提出日時 2024-03-19 15:13:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 920 ms / 2,000 ms
コード長 502 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,220 KB
最終ジャッジ日時 2024-03-19 15:13:44
合計ジャッジ時間 6,866 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,332 KB
testcase_01 AC 36 ms
53,332 KB
testcase_02 AC 36 ms
53,332 KB
testcase_03 AC 36 ms
53,332 KB
testcase_04 AC 55 ms
64,060 KB
testcase_05 AC 37 ms
53,332 KB
testcase_06 AC 919 ms
75,220 KB
testcase_07 AC 917 ms
75,220 KB
testcase_08 AC 920 ms
75,220 KB
testcase_09 AC 43 ms
59,704 KB
testcase_10 AC 45 ms
61,840 KB
testcase_11 AC 43 ms
59,704 KB
testcase_12 AC 200 ms
68,164 KB
testcase_13 AC 129 ms
68,168 KB
testcase_14 AC 325 ms
70,224 KB
testcase_15 AC 108 ms
66,116 KB
testcase_16 AC 103 ms
66,116 KB
testcase_17 AC 74 ms
64,052 KB
testcase_18 AC 113 ms
66,116 KB
testcase_19 AC 59 ms
64,060 KB
testcase_20 AC 283 ms
70,224 KB
testcase_21 AC 591 ms
73,556 KB
testcase_22 AC 37 ms
53,332 KB
testcase_23 AC 36 ms
53,332 KB
testcase_24 AC 37 ms
53,332 KB
testcase_25 AC 36 ms
53,332 KB
testcase_26 AC 36 ms
53,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
A=list(map(int,input().split()))
times=[]
dat=[i for i in range(N)]
times.append(dat)
for i in range(M):
    dat[A[i]-1],dat[A[i]]=dat[A[i]],dat[A[i]-1]
    times.append(dat)
dp=[10**9 for _ in range(N)]
dp[0]=0
for i in range(N):
    for j in range(N):
        dp[i]=min(dp[i],dp[j]+abs(j-i))
for i in range(M-1,-1,-1):
    dp[A[i]-1],dp[A[i]]=dp[A[i]],dp[A[i]-1]
    for i in range(N):
        for j in range(N):
            dp[i]=min(dp[i],dp[j]+abs(j-i))
print(*dp[1:])
0