結果

問題 No.2617 容量3のナップザック
ユーザー titiatitia
提出日時 2024-01-30 05:42:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 878 bytes
コンパイル時間 3,138 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 250,184 KB
最終ジャッジ日時 2024-01-30 05:42:24
合計ジャッジ時間 12,684 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 40 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 WA -
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 39 ms
53,460 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 281 ms
191,740 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 67 ms
74,784 KB
testcase_25 AC 253 ms
199,516 KB
testcase_26 AC 307 ms
206,460 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 170 ms
146,324 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 471 ms
246,640 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 415 ms
243,668 KB
testcase_40 WA -
testcase_41 AC 195 ms
243,796 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()

ANS=0
for i in range(K):
    for j in range(3):
        if V[j]==[]:
            V[j]=[0]

    v3=V[2][-1]
    v12=V[0][-1]+V[1][-1]
    v1=0

    for j in range(3):
        if len(V[0])-1-j>=0:
            v1+=V[0][len(V[0])-1-j]

    MAX=max(v1,v12,v3)

    if MAX==v3:
        ANS+=V[2].pop()
    elif MAX==v12:
        ANS+=V[1].pop()
        ANS+=V[0].pop()
    else:
        ANS+=V[0].pop()
        if V[0]==[]:
            V[0].append(0)
        ANS+=V[0].pop()
        if V[0]==[]:
            V[0].append(0)
        ANS+=V[0].pop()
        if V[0]==[]:
            V[0].append(0)

print(ANS)
        
0