結果

問題 No.2617 容量3のナップザック
ユーザー 👑 kmjpkmjp
提出日時 2024-01-27 00:55:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,504 ms / 2,000 ms
コード長 1,783 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 215,708 KB
実行使用メモリ 212,836 KB
最終ジャッジ日時 2024-01-27 00:55:44
合計ジャッジ時間 15,535 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 593 ms
90,964 KB
testcase_13 AC 217 ms
36,172 KB
testcase_14 AC 539 ms
84,120 KB
testcase_15 AC 162 ms
30,544 KB
testcase_16 AC 777 ms
115,464 KB
testcase_17 AC 375 ms
59,952 KB
testcase_18 AC 297 ms
50,108 KB
testcase_19 AC 38 ms
11,900 KB
testcase_20 AC 183 ms
34,404 KB
testcase_21 AC 259 ms
47,692 KB
testcase_22 AC 205 ms
36,696 KB
testcase_23 AC 478 ms
73,112 KB
testcase_24 AC 14 ms
7,292 KB
testcase_25 AC 273 ms
49,208 KB
testcase_26 AC 779 ms
120,816 KB
testcase_27 AC 215 ms
36,104 KB
testcase_28 AC 10 ms
6,548 KB
testcase_29 AC 98 ms
22,688 KB
testcase_30 AC 193 ms
40,964 KB
testcase_31 AC 431 ms
67,488 KB
testcase_32 AC 322 ms
57,288 KB
testcase_33 AC 469 ms
70,092 KB
testcase_34 AC 567 ms
88,532 KB
testcase_35 AC 391 ms
58,416 KB
testcase_36 AC 1,504 ms
212,836 KB
testcase_37 AC 582 ms
89,980 KB
testcase_38 AC 234 ms
37,800 KB
testcase_39 AC 508 ms
86,012 KB
testcase_40 AC 434 ms
66,868 KB
testcase_41 AC 231 ms
70,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll N,K,seed,A,B,M;
ll F[2020202];
vector<ll> W[4];
multiset<ll> L[3],R[3];
ll S[3];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>seed>>A>>B>>M;
	F[0]=seed;
	FOR(i,2*N) {
		F[i+1]=(F[i]*A+B)%M;
	}
	FOR(i,N) {
		x=F[i]%3+1;
		W[x].push_back(F[N+i]*x);
	}
	FOR(i,K+1) W[2].push_back(0);
	FOR(i,3*K+10) W[1].push_back(0);
	FOR(i,4) {
		sort(ALL(W[i]));
		reverse(ALL(W[i]));
	}
	FOR(i,3) {
		vector<ll> C;
		FOR(j,W[3].size()) {
			C.push_back(W[3][j]);
		}
		FOR(j,K+1) {
			ll a=W[1][i+j*3]+W[1][i+j*3+1]+W[1][i+j*3+2];
			C.push_back(a);
		}
		sort(ALL(C));
		reverse(ALL(C));
		FOR(j,K) L[i].insert(C[j]), S[i]+=C[j];
	}
	ll ma=0;
	ll sum=0;
	FOR(i,K+1) {
		if(i) sum+=W[2][i-1]+W[1][i-1];
		x=i%3;
		if(i>=3) {
			ll a=W[1][i-1]+W[1][i-2]+W[1][i-3];
			if(L[x].count(a)) {
				L[x].erase(L[x].find(a));
				S[x]-=a;
			}
		}
		while(L[x].size()>K-i) {
			ll a=*L[x].begin();
			S[x]-=a;
			L[x].erase(L[x].begin());
		}
		ma=max(ma,sum+S[x]);
	}
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0