結果

問題 No.2673 A present from B
ユーザー sasa8uyauyasasa8uyauya
提出日時 2024-03-15 23:30:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,399 ms / 2,000 ms
コード長 323 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,380 KB
最終ジャッジ日時 2024-03-15 23:30:37
合計ジャッジ時間 8,764 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 50 ms
62,112 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 1,358 ms
75,380 KB
testcase_07 AC 1,345 ms
75,380 KB
testcase_08 AC 1,399 ms
75,376 KB
testcase_09 AC 45 ms
59,832 KB
testcase_10 AC 45 ms
62,104 KB
testcase_11 AC 43 ms
59,832 KB
testcase_12 AC 298 ms
70,388 KB
testcase_13 AC 176 ms
68,324 KB
testcase_14 AC 526 ms
72,436 KB
testcase_15 AC 146 ms
66,260 KB
testcase_16 AC 139 ms
66,260 KB
testcase_17 AC 71 ms
66,260 KB
testcase_18 AC 157 ms
68,308 KB
testcase_19 AC 61 ms
64,196 KB
testcase_20 AC 435 ms
70,356 KB
testcase_21 AC 866 ms
75,380 KB
testcase_22 AC 36 ms
53,460 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 AC 37 ms
53,460 KB
testcase_25 AC 38 ms
53,460 KB
testcase_26 AC 37 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
a=list(map(int,input().split()))
p=list(range(n))
for v in a:
	p[v-1],p[v]=p[v],p[v-1]
q=[n]*n
for i in range(n):
  q[p[i]]=i
for v in a[::-1]:
  p[v-1],p[v]=p[v],p[v-1]
  nq=q.copy()
  for i in range(n):
    for j in range(n):
      nq[p[i]]=min(nq[p[i]],q[p[j]]+abs(i-j))
  q=nq
print(*q[1:])
0