結果

問題 No.2673 A present from B
ユーザー titiatitia
提出日時 2024-03-16 03:29:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,341 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 75,508 KB
最終ジャッジ日時 2024-03-16 03:29:56
合計ジャッジ時間 9,129 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 41 ms
53,460 KB
testcase_04 AC 51 ms
62,108 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 1,339 ms
75,492 KB
testcase_07 AC 1,341 ms
75,496 KB
testcase_08 AC 1,240 ms
75,500 KB
testcase_09 AC 46 ms
62,100 KB
testcase_10 AC 48 ms
62,228 KB
testcase_11 AC 44 ms
59,956 KB
testcase_12 AC 296 ms
70,500 KB
testcase_13 AC 176 ms
70,512 KB
testcase_14 AC 474 ms
72,568 KB
testcase_15 AC 148 ms
68,324 KB
testcase_16 AC 140 ms
68,324 KB
testcase_17 AC 71 ms
66,396 KB
testcase_18 AC 159 ms
68,324 KB
testcase_19 AC 61 ms
64,192 KB
testcase_20 AC 437 ms
72,564 KB
testcase_21 AC 870 ms
75,508 KB
testcase_22 AC 38 ms
53,460 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 AC 44 ms
53,460 KB
testcase_25 AC 44 ms
53,456 KB
testcase_26 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
A=list(map(int,input().split()))

L=list(range(N))

for a in A:
    x=a
    y=a-1

    L[x],L[y]=L[y],L[x]

ANS=[1<<60]*N

for i in range(N):
    ANS[L[i]]=i

for a in A[::-1]:
    x=a
    y=a-1

    L[x],L[y]=L[y],L[x]

    ANS2=ANS[:]

    for i in range(N):
        for j in range(N):
            ANS2[L[j]]=min(ANS2[L[j]],ANS[L[i]]+abs(i-j))

    ANS=ANS2

print(*ANS[1:])
    
0