結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 37 ms
53,460 KB
testcase_04 AC 79 ms
73,052 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 45 ms
61,960 KB
testcase_10 AC 46 ms
61,952 KB
testcase_11 AC 43 ms
59,708 KB
testcase_12 AC 478 ms
76,500 KB
testcase_13 AC 311 ms
76,492 KB
testcase_14 AC 809 ms
76,736 KB
testcase_15 AC 241 ms
76,244 KB
testcase_16 AC 227 ms
76,116 KB
testcase_17 AC 117 ms
74,432 KB
testcase_18 AC 258 ms
76,120 KB
testcase_19 AC 87 ms
73,556 KB
testcase_20 AC 732 ms
76,620 KB
testcase_21 AC 1,402 ms
77,372 KB
testcase_22 AC 37 ms
53,460 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 AC 36 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()))
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] or j==A[i-1]+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] or j==A[i-1]+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