結果

問題 No.2617 容量3のナップザック
ユーザー mkawa2mkawa2
提出日時 2024-01-26 22:14:38
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,661 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 256,644 KB
最終ジャッジ日時 2024-01-26 22:14:58
合計ジャッジ時間 13,855 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 RE -
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 36 ms
53,460 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 498 ms
252,872 KB
testcase_14 RE -
testcase_15 AC 339 ms
255,684 KB
testcase_16 RE -
testcase_17 AC 429 ms
254,896 KB
testcase_18 AC 414 ms
255,024 KB
testcase_19 AC 98 ms
100,920 KB
testcase_20 AC 433 ms
252,532 KB
testcase_21 RE -
testcase_22 AC 480 ms
252,528 KB
testcase_23 AC 537 ms
252,040 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 86 ms
80,136 KB
testcase_29 AC 188 ms
169,340 KB
testcase_30 AC 479 ms
249,312 KB
testcase_31 RE -
testcase_32 AC 559 ms
255,400 KB
testcase_33 AC 563 ms
254,872 KB
testcase_34 AC 620 ms
254,444 KB
testcase_35 AC 536 ms
254,372 KB
testcase_36 RE -
testcase_37 AC 591 ms
256,080 KB
testcase_38 AC 512 ms
254,412 KB
testcase_39 RE -
testcase_40 AC 584 ms
254,736 KB
testcase_41 RE -
権限があれば一括ダウンロードができます

ソースコード

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)
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