結果

問題 No.2423 Merge Stones
ユーザー とりゐとりゐ
提出日時 2023-08-12 15:10:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,933 ms / 4,000 ms
コード長 1,035 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 82,860 KB
実行使用メモリ 77,396 KB
最終ジャッジ日時 2024-04-30 08:29:36
合計ジャッジ時間 167,681 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,760 KB
testcase_01 AC 66 ms
69,080 KB
testcase_02 AC 65 ms
68,444 KB
testcase_03 AC 63 ms
67,564 KB
testcase_04 AC 40 ms
53,376 KB
testcase_05 AC 50 ms
62,048 KB
testcase_06 AC 67 ms
68,656 KB
testcase_07 AC 68 ms
69,464 KB
testcase_08 AC 44 ms
55,708 KB
testcase_09 AC 40 ms
53,044 KB
testcase_10 AC 64 ms
66,564 KB
testcase_11 AC 3,925 ms
77,064 KB
testcase_12 AC 459 ms
74,400 KB
testcase_13 AC 3,760 ms
76,764 KB
testcase_14 AC 2,106 ms
77,132 KB
testcase_15 AC 923 ms
77,272 KB
testcase_16 AC 3,235 ms
76,940 KB
testcase_17 AC 2,109 ms
76,836 KB
testcase_18 AC 3,243 ms
77,188 KB
testcase_19 AC 442 ms
73,092 KB
testcase_20 AC 2,096 ms
76,828 KB
testcase_21 AC 3,750 ms
77,032 KB
testcase_22 AC 2,109 ms
76,812 KB
testcase_23 AC 914 ms
76,968 KB
testcase_24 AC 927 ms
76,908 KB
testcase_25 AC 922 ms
76,892 KB
testcase_26 AC 932 ms
77,148 KB
testcase_27 AC 2,675 ms
77,128 KB
testcase_28 AC 3,779 ms
77,136 KB
testcase_29 AC 3,224 ms
77,080 KB
testcase_30 AC 2,134 ms
76,988 KB
testcase_31 AC 2,121 ms
76,912 KB
testcase_32 AC 3,788 ms
76,916 KB
testcase_33 AC 938 ms
77,232 KB
testcase_34 AC 2,685 ms
77,300 KB
testcase_35 AC 2,087 ms
76,916 KB
testcase_36 AC 2,105 ms
77,040 KB
testcase_37 AC 924 ms
77,136 KB
testcase_38 AC 918 ms
77,176 KB
testcase_39 AC 3,749 ms
76,824 KB
testcase_40 AC 3,225 ms
76,916 KB
testcase_41 AC 2,648 ms
76,896 KB
testcase_42 AC 3,736 ms
77,396 KB
testcase_43 AC 437 ms
73,132 KB
testcase_44 AC 3,726 ms
76,872 KB
testcase_45 AC 911 ms
76,944 KB
testcase_46 AC 2,650 ms
76,800 KB
testcase_47 AC 916 ms
77,152 KB
testcase_48 AC 929 ms
77,140 KB
testcase_49 AC 435 ms
73,992 KB
testcase_50 AC 445 ms
74,704 KB
testcase_51 AC 3,384 ms
77,024 KB
testcase_52 AC 3,400 ms
77,192 KB
testcase_53 AC 3,913 ms
77,052 KB
testcase_54 AC 3,374 ms
77,064 KB
testcase_55 AC 3,892 ms
77,168 KB
testcase_56 AC 3,213 ms
77,000 KB
testcase_57 AC 3,219 ms
76,972 KB
testcase_58 AC 3,734 ms
77,200 KB
testcase_59 AC 3,727 ms
77,152 KB
testcase_60 AC 3,223 ms
76,808 KB
testcase_61 AC 3,930 ms
77,132 KB
testcase_62 AC 3,905 ms
77,180 KB
testcase_63 AC 3,886 ms
77,296 KB
testcase_64 AC 3,884 ms
77,128 KB
testcase_65 AC 3,884 ms
77,048 KB
testcase_66 AC 3,925 ms
77,100 KB
testcase_67 AC 3,915 ms
77,196 KB
testcase_68 AC 3,907 ms
77,104 KB
testcase_69 AC 3,933 ms
77,280 KB
testcase_70 AC 3,899 ms
77,392 KB
testcase_71 AC 3,759 ms
77,012 KB
testcase_72 AC 3,740 ms
76,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp=[[0]*n for i in range(n)]
for d in range(n):
  for l in range(n):
    r=l+d
    R=r%n
    if l==r:
      dp[l][r]=1<<c[l]
      continue
    for m in range(l,r):
      M0=m%n
      M1=(m+1)%n
      res=dp[l][M0]&dp[M1][R]
      for j in range(1,k+1):
        dp[l][R]|=(dp[l][M0]<<j)&dp[M1][R]
        dp[l][R]|=(dp[M1][R]<<j)&dp[l][M0]
        dp[l][R]|=(dp[l][M0]>>j)&dp[M1][R]
        dp[l][R]|=(dp[M1][R]>>j)&dp[l][M0]
      
      tmp1=dp[l][M0]
      tmp2=dp[l][M0]
      for _ in range(k):
        tmp1>>=1
        tmp2<<=1
        res|=(tmp1|tmp2)&dp[M1][R]
      
      tmp1=dp[M1][R]
      tmp2=dp[M1][R]
      for _ in range(k):
        tmp1>>=1
        tmp2<<=1
        res|=(tmp1|tmp2)&dp[l][M0]
      
      dp[l][R]|=res

ans=0
for l in range(n):
  for r in range(n):
    if dp[l][r]:
      res=0
      if r<l:
        r+=n
      for i in range(l,r+1):
        res+=a[i%n]
      ans=max(ans,res)

print(ans)
0