結果

問題 No.2617 容量3のナップザック
ユーザー とりゐとりゐ
提出日時 2024-01-26 22:07:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 438 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 255,800 KB
最終ジャッジ日時 2024-01-26 22:08:13
合計ジャッジ時間 11,401 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 34 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 35 ms
53,460 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 36 ms
53,460 KB
testcase_12 AC 360 ms
198,872 KB
testcase_13 AC 343 ms
221,428 KB
testcase_14 AC 319 ms
196,480 KB
testcase_15 AC 271 ms
172,780 KB
testcase_16 AC 272 ms
198,328 KB
testcase_17 AC 301 ms
204,832 KB
testcase_18 AC 295 ms
199,176 KB
testcase_19 AC 97 ms
91,332 KB
testcase_20 AC 343 ms
209,968 KB
testcase_21 AC 194 ms
145,016 KB
testcase_22 AC 351 ms
232,308 KB
testcase_23 AC 359 ms
239,116 KB
testcase_24 AC 62 ms
70,840 KB
testcase_25 AC 229 ms
170,612 KB
testcase_26 AC 284 ms
170,112 KB
testcase_27 AC 171 ms
131,236 KB
testcase_28 AC 74 ms
75,676 KB
testcase_29 AC 154 ms
123,920 KB
testcase_30 AC 353 ms
215,816 KB
testcase_31 AC 304 ms
204,696 KB
testcase_32 AC 359 ms
239,828 KB
testcase_33 AC 391 ms
254,136 KB
testcase_34 AC 400 ms
242,772 KB
testcase_35 AC 386 ms
240,596 KB
testcase_36 AC 438 ms
255,800 KB
testcase_37 AC 399 ms
253,624 KB
testcase_38 AC 378 ms
241,924 KB
testcase_39 AC 378 ms
247,912 KB
testcase_40 AC 398 ms
252,296 KB
testcase_41 AC 150 ms
226,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K,seed,a,b,m=map(int,input().split())
w=[0]*N
f=seed
for i in range(N):
  w[i]=f%3+1
  f=(a*f+b)%m

v=[0]*N
for i in range(N):
  v[i]=f*w[i]
  f=(a*f+b)%m

w1=[]
w2=[]
w3=[]
for i in range(N):
  if w[i]==1:
    w1.append(v[i])
  if w[i]==2:
    w2.append(v[i])
  if w[i]==3:
    w3.append(v[i])

w1.sort(reverse=True)
w2.sort(reverse=True)
w3.sort(reverse=True)

w1+=[0]*max(0,(3*N+10-len(w1)))
w2+=[0]*max(0,N+10-len(w2))
w3+=[0]*max(0,N+10-len(w3))


ans=0
res=[0]
idx1=0
idx2=0
tmp=0
for i in range(1,K+1):
  tmp+=w1[idx1]+w1[idx1+1]+w1[idx1+2]
  idx1+=3
  while idx2<i and w2[idx2]>=w1[idx1-1]+w1[idx1-2]:
    tmp+=w2[idx2]-w1[idx1-1]-w1[idx1-2]
    idx2+=1
    idx1-=2
  while idx2>0 and w1[idx1]+w1[idx1+1]>w2[idx2-1]:
    tmp+=w1[idx1]+w1[idx1+1]-w2[idx2-1]
    idx2-=1
    idx1+=2
  res.append(tmp)

cum3=0
for i in range(K+1):
  ans=max(ans,res[K-i]+cum3)
  cum3+=w3[i]

print(ans)
0