結果

問題 No.2423 Merge Stones
ユーザー とりゐとりゐ
提出日時 2023-08-12 14:31:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 948 bytes
コンパイル時間 888 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 86,316 KB
最終ジャッジ日時 2024-04-30 06:25:32
合計ジャッジ時間 38,978 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
53,216 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 32 ms
53,148 KB
testcase_05 AC 37 ms
60,376 KB
testcase_06 AC 37 ms
60,340 KB
testcase_07 WA -
testcase_08 AC 32 ms
53,204 KB
testcase_09 AC 33 ms
53,244 KB
testcase_10 AC 36 ms
60,228 KB
testcase_11 AC 1,538 ms
85,868 KB
testcase_12 AC 140 ms
84,756 KB
testcase_13 AC 142 ms
84,556 KB
testcase_14 AC 133 ms
84,604 KB
testcase_15 AC 129 ms
84,680 KB
testcase_16 AC 137 ms
84,664 KB
testcase_17 AC 135 ms
84,516 KB
testcase_18 AC 130 ms
84,552 KB
testcase_19 AC 135 ms
84,688 KB
testcase_20 AC 136 ms
84,608 KB
testcase_21 AC 130 ms
84,660 KB
testcase_22 AC 132 ms
84,704 KB
testcase_23 AC 134 ms
84,712 KB
testcase_24 AC 132 ms
84,560 KB
testcase_25 AC 132 ms
84,644 KB
testcase_26 AC 132 ms
84,632 KB
testcase_27 AC 131 ms
84,528 KB
testcase_28 AC 138 ms
84,612 KB
testcase_29 WA -
testcase_30 AC 130 ms
84,644 KB
testcase_31 AC 129 ms
84,696 KB
testcase_32 AC 133 ms
84,632 KB
testcase_33 AC 140 ms
84,548 KB
testcase_34 AC 132 ms
84,788 KB
testcase_35 AC 129 ms
84,788 KB
testcase_36 AC 132 ms
84,620 KB
testcase_37 AC 131 ms
84,684 KB
testcase_38 AC 128 ms
84,568 KB
testcase_39 WA -
testcase_40 AC 129 ms
84,680 KB
testcase_41 AC 130 ms
84,540 KB
testcase_42 AC 132 ms
84,652 KB
testcase_43 AC 136 ms
84,484 KB
testcase_44 WA -
testcase_45 AC 132 ms
84,576 KB
testcase_46 AC 144 ms
84,616 KB
testcase_47 AC 131 ms
84,620 KB
testcase_48 AC 134 ms
84,560 KB
testcase_49 AC 130 ms
84,744 KB
testcase_50 AC 129 ms
84,556 KB
testcase_51 AC 1,634 ms
85,688 KB
testcase_52 AC 1,547 ms
85,676 KB
testcase_53 AC 1,552 ms
86,316 KB
testcase_54 AC 1,576 ms
85,972 KB
testcase_55 AC 1,652 ms
86,104 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 1,528 ms
85,840 KB
testcase_62 AC 1,560 ms
85,816 KB
testcase_63 AC 1,521 ms
85,980 KB
testcase_64 AC 1,568 ms
85,824 KB
testcase_65 AC 1,570 ms
86,024 KB
testcase_66 AC 1,547 ms
86,024 KB
testcase_67 AC 1,530 ms
85,980 KB
testcase_68 AC 1,551 ms
86,200 KB
testcase_69 AC 1,543 ms
85,632 KB
testcase_70 AC 1,311 ms
86,012 KB
testcase_71 AC 752 ms
85,936 KB
testcase_72 AC 732 ms
85,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k=map(int,input().split())
a=list(map(int,input().split()))
c=list(map(lambda x:int(x)-1,input().split()))

def check(l0,r0,l1,r1):
  if l0==inf or l1==inf:
    return False
  return min(r0,r1)+k>=max(l0,l1)

ans=0
inf=1<<60
dp=[[-inf]*n for i in range(n)]
color=[[[inf,-1] for i in range(n)] for j in range(n)]
for d in range(n):
  for l in range(n):
    r=(l+d)%n
    if l==r:
      dp[l][r]=a[l]
      color[l][r]=[c[l],c[l]]
      continue
    for m in range(l,l+d):
      m%=n
      if dp[l][m]==-inf or dp[(m+1)%n][r]==-inf:
        continue
      l0,r0=color[l][m]
      l1,r1=color[(m+1)%n][r]
      if check(l0,r0,l1,r1):
        dp[l][r]=max(dp[l][r],dp[l][m]+dp[(m+1)%n][r])
        # color[l][r][0]=[min(l0,l1),max(r0,r1)]
        color[l][r][0]=min(color[l][r][0],l0,l1)
        color[l][r][1]=max(color[l][r][1],r0,r1)
        # print(l,m,r,l0,r0,l1,r1)

for l in range(n):
  for r in range(n):
    ans=max(ans,dp[l][r])

print(ans)
0