結果

問題 No.2423 Merge Stones
ユーザー とりゐとりゐ
提出日時 2023-08-12 14:17:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 824 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,504 KB
実行使用メモリ 86,296 KB
最終ジャッジ日時 2024-04-30 05:36:14
合計ジャッジ時間 37,269 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,352 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 36 ms
52,920 KB
testcase_05 AC 40 ms
60,468 KB
testcase_06 AC 43 ms
59,588 KB
testcase_07 WA -
testcase_08 AC 36 ms
53,628 KB
testcase_09 AC 36 ms
52,488 KB
testcase_10 AC 44 ms
59,628 KB
testcase_11 AC 1,379 ms
86,252 KB
testcase_12 AC 133 ms
73,992 KB
testcase_13 AC 134 ms
73,620 KB
testcase_14 AC 134 ms
73,696 KB
testcase_15 AC 133 ms
74,228 KB
testcase_16 AC 133 ms
73,380 KB
testcase_17 AC 132 ms
74,888 KB
testcase_18 AC 134 ms
73,444 KB
testcase_19 AC 132 ms
73,416 KB
testcase_20 AC 132 ms
73,276 KB
testcase_21 AC 134 ms
73,828 KB
testcase_22 AC 132 ms
73,504 KB
testcase_23 AC 133 ms
73,268 KB
testcase_24 AC 132 ms
73,372 KB
testcase_25 AC 134 ms
74,080 KB
testcase_26 AC 132 ms
73,292 KB
testcase_27 AC 134 ms
73,336 KB
testcase_28 AC 143 ms
78,348 KB
testcase_29 WA -
testcase_30 AC 134 ms
73,664 KB
testcase_31 AC 133 ms
73,796 KB
testcase_32 AC 134 ms
73,880 KB
testcase_33 AC 132 ms
73,804 KB
testcase_34 AC 139 ms
73,372 KB
testcase_35 AC 134 ms
74,640 KB
testcase_36 AC 133 ms
73,384 KB
testcase_37 AC 134 ms
73,696 KB
testcase_38 AC 133 ms
73,400 KB
testcase_39 WA -
testcase_40 AC 134 ms
73,928 KB
testcase_41 AC 134 ms
73,648 KB
testcase_42 AC 133 ms
74,552 KB
testcase_43 AC 132 ms
73,528 KB
testcase_44 WA -
testcase_45 AC 133 ms
73,368 KB
testcase_46 AC 133 ms
73,380 KB
testcase_47 AC 133 ms
73,188 KB
testcase_48 AC 132 ms
73,872 KB
testcase_49 AC 133 ms
73,508 KB
testcase_50 AC 133 ms
73,580 KB
testcase_51 AC 1,633 ms
85,984 KB
testcase_52 AC 1,640 ms
86,284 KB
testcase_53 AC 1,549 ms
86,124 KB
testcase_54 AC 1,612 ms
86,296 KB
testcase_55 AC 1,566 ms
85,988 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 1,460 ms
86,108 KB
testcase_62 AC 1,455 ms
86,144 KB
testcase_63 AC 1,434 ms
86,224 KB
testcase_64 AC 1,409 ms
86,020 KB
testcase_65 AC 1,407 ms
85,960 KB
testcase_66 AC 1,490 ms
85,872 KB
testcase_67 AC 1,341 ms
86,024 KB
testcase_68 AC 1,394 ms
85,892 KB
testcase_69 AC 1,457 ms
86,168 KB
testcase_70 AC 1,193 ms
85,580 KB
testcase_71 AC 744 ms
82,688 KB
testcase_72 AC 733 ms
82,456 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==-1 or l1==-1:
    return False
  return min(r0,r1)+k>=max(l0,l1)

ans=0
inf=1<<60
dp=[[-inf]*n for i in range(n)]
color=[[-1,-1]*n for i 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]=[min(l0,l1),max(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