結果

問題 No.2673 A present from B
ユーザー ゼットゼット
提出日時 2024-03-15 22:12:13
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 613 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,876 KB
最終ジャッジ日時 2024-03-15 22:12:30
合計ジャッジ時間 12,901 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 70 ms
70,964 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 46 ms
61,968 KB
testcase_10 WA -
testcase_11 AC 44 ms
61,840 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 82 ms
73,060 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 39 ms
53,460 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 37 ms
53,460 KB
testcase_26 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
A=list(map(int,input().split()))
for i in range(M):
  A[i]-=1
dp=[[10**10]*N for i in range(M+1)]
for j in range(N):
  dp[M][j]=j
for i in range(M,0,-1):
  for j in range(N):
    for k in range(N):
      if k<=j:
        if k<=A[i-1]<j:
          cost1=j-k-1
        else:
          cost1=j-k
      else:
        cost1=10**10
      if j<=k:
        if j<=A[i-1]<k:
          cost2=k-j-1
        else:
          cost2=k-j
      else:
        cost2=10**10
      dp[i-1][j]=min(dp[i-1][j],dp[i][k]+min(cost1,cost2))
result=[]
for i in range(1,N):
  result.append(dp[0][i])
print(*result)
0