結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 81 ms
73,056 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 47 ms
61,952 KB
testcase_10 WA -
testcase_11 AC 45 ms
59,708 KB
testcase_12 AC 519 ms
76,360 KB
testcase_13 WA -
testcase_14 AC 823 ms
76,736 KB
testcase_15 AC 232 ms
76,116 KB
testcase_16 AC 229 ms
76,252 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 84 ms
73,056 KB
testcase_20 AC 704 ms
76,488 KB
testcase_21 AC 1,500 ms
77,368 KB
testcase_22 AC 37 ms
53,460 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 WA -
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()))
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:
          if j==k and j==A[i-1]:
            cost1=1
            continue
          cost1=j-k
      else:
        cost1=10**10
      if j<=k:
        if j<=A[i-1]<k:
          cost2=k-j-1
        else:
          if j==A[i-1] and j==k:
            cost2=1
            continue
          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