結果

問題 No.2617 容量3のナップザック
ユーザー mkawa2mkawa2
提出日時 2024-01-26 22:18:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 613 ms / 2,000 ms
コード長 1,668 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 256,132 KB
最終ジャッジ日時 2024-01-26 22:18:15
合計ジャッジ時間 14,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 37 ms
53,456 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 37 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 39 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 550 ms
252,784 KB
testcase_13 AC 462 ms
252,872 KB
testcase_14 AC 511 ms
254,472 KB
testcase_15 AC 343 ms
255,548 KB
testcase_16 AC 352 ms
242,916 KB
testcase_17 AC 462 ms
254,896 KB
testcase_18 AC 419 ms
255,024 KB
testcase_19 AC 99 ms
101,944 KB
testcase_20 AC 432 ms
252,532 KB
testcase_21 AC 301 ms
190,404 KB
testcase_22 AC 484 ms
252,528 KB
testcase_23 AC 540 ms
252,040 KB
testcase_24 AC 82 ms
84,204 KB
testcase_25 AC 270 ms
238,236 KB
testcase_26 AC 363 ms
255,860 KB
testcase_27 AC 269 ms
164,792 KB
testcase_28 AC 91 ms
80,384 KB
testcase_29 AC 189 ms
169,340 KB
testcase_30 AC 450 ms
249,312 KB
testcase_31 AC 503 ms
254,440 KB
testcase_32 AC 565 ms
256,132 KB
testcase_33 AC 577 ms
255,612 KB
testcase_34 AC 606 ms
255,180 KB
testcase_35 AC 553 ms
255,104 KB
testcase_36 AC 575 ms
254,348 KB
testcase_37 AC 608 ms
255,256 KB
testcase_38 AC 507 ms
255,140 KB
testcase_39 AC 450 ms
247,584 KB
testcase_40 AC 613 ms
255,464 KB
testcase_41 AC 280 ms
255,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

n,k,seed,a,b,m=LI()
ff=[seed]
for _ in range(2*n):
    ff.append((ff[-1]*a%m+b)%m)
ww=[f%3+1 for f in ff]
vv=[ww[i]*ff[n+i] for i in range(n)]

v1=[]
v2=[]
v3=[]
for w,v in zip(ww,vv):
    if w==1:v1.append(v)
    if w==2:v2.append(v)
    if w==3:v3.append(v)

def tocs(vv):
    vv.sort(reverse=True)
    cs=[0]
    for v in vv:cs.append(cs[-1]+v)
    return cs

s1=tocs(v1)
s2=tocs(v2)+[-inf]
s3=tocs(v3)
# pDB(v1)
# pDB(s1)

def binary_search(l, r, minimize,c):
    if minimize: l -= 1
    else: r += 1
    while l+1 < r:
        m = (l+r)//2
        if ok(m,c) ^ minimize: l = m
        else: r = m
    if minimize: return r
    return l

def ok(b,c):
    return bc2val(b,c)>=bc2val(b+1,c)

def bc2val(b,c):
    a=min(len(v1),(k-c-b)*3+b)
    return s3[c]+s2[b]+s1[a]

ans=0
for c in range(min(len(v3),k)+1):
    b=binary_search(0,min(k-c,len(s2)),True,c)
    ans=max(ans,bc2val(b,c))

print(ans)
0