結果

問題 No.2617 容量3のナップザック
ユーザー titiatitia
提出日時 2024-01-30 06:04:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,012 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 3,076 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 254,884 KB
最終ジャッジ日時 2024-01-30 06:05:03
合計ジャッジ時間 22,983 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 37 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 36 ms
53,460 KB
testcase_12 AC 483 ms
251,824 KB
testcase_13 AC 389 ms
248,668 KB
testcase_14 AC 423 ms
252,384 KB
testcase_15 AC 294 ms
246,868 KB
testcase_16 AC 555 ms
227,788 KB
testcase_17 AC 426 ms
254,656 KB
testcase_18 AC 348 ms
254,884 KB
testcase_19 AC 95 ms
98,044 KB
testcase_20 AC 369 ms
250,180 KB
testcase_21 AC 256 ms
179,568 KB
testcase_22 AC 409 ms
247,628 KB
testcase_23 AC 519 ms
247,628 KB
testcase_24 AC 72 ms
78,080 KB
testcase_25 AC 253 ms
225,356 KB
testcase_26 AC 619 ms
242,788 KB
testcase_27 AC 222 ms
156,076 KB
testcase_28 AC 68 ms
74,268 KB
testcase_29 AC 180 ms
161,464 KB
testcase_30 AC 386 ms
247,972 KB
testcase_31 AC 427 ms
254,388 KB
testcase_32 AC 446 ms
246,636 KB
testcase_33 AC 570 ms
246,636 KB
testcase_34 AC 550 ms
246,636 KB
testcase_35 AC 496 ms
246,636 KB
testcase_36 AC 1,012 ms
246,636 KB
testcase_37 AC 569 ms
246,636 KB
testcase_38 AC 439 ms
246,636 KB
testcase_39 AC 458 ms
243,792 KB
testcase_40 AC 536 ms
246,636 KB
testcase_41 AC 237 ms
243,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,K,seed,a,b,m=map(int,input().split())

F=[seed]

for i in range(2*N-1):
    F.append((F[-1]*a+b)%m)

V=[[],[],[]]

for i in range(N):
    w=F[i]%3+1
    v=F[i+N]*w

    V[w-1].append(v)
    
for i in range(3):
    V[i].sort(reverse=True)

S=[[0],[0],[0]]
for i in range(3):
    for j in range(len(V[i])):
        S[i].append(S[i][-1]+V[i][j])


ANS=0
# 3を何個取るか三分探索

def calc(three):
    ANS=S[2][three]

    rest=K-three

    MAX=0
    for i in range(rest+1):
        rest2=i+(rest-i)*3
        score=0

        if i<len(S[1]):
            score=S[1][i]
        else:
            score=S[1][-1]

        if rest2<len(S[0]):
            score+=S[0][rest2]
        else:
            score+=S[0][-1]

        if MAX<score:
            MAX=score

    return MAX+ANS

MIN=0
MAX=min(K,len(V[2]))

while MAX-MIN>5:
    mid1=MIN+(MAX-MIN)//3
    mid2=MIN+(MAX-MIN)//3*2

    c1=calc(mid1)
    c2=calc(mid2)

    if c1>c2:
        MAX=mid2
    else:
        MIN=mid1

for i in range(MIN,MAX+1):
    ANS=max(ANS,calc(i))

print(ANS)
0