結果

問題 No.2617 容量3のナップザック
ユーザー 👑 kmjpkmjp
提出日時 2024-01-27 00:45:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,869 bytes
コンパイル時間 3,521 ms
コンパイル使用メモリ 215,420 KB
実行使用メモリ 255,824 KB
最終ジャッジ日時 2024-01-27 00:46:15
合計ジャッジ時間 26,208 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 1,330 ms
119,468 KB
testcase_13 AC 416 ms
71,856 KB
testcase_14 AC 1,212 ms
111,984 KB
testcase_15 AC 389 ms
56,144 KB
testcase_16 AC 1,762 ms
132,832 KB
testcase_17 AC 895 ms
88,948 KB
testcase_18 AC 657 ms
79,932 KB
testcase_19 AC 66 ms
11,644 KB
testcase_20 AC 426 ms
66,216 KB
testcase_21 AC 568 ms
60,996 KB
testcase_22 AC 507 ms
74,272 KB
testcase_23 AC 1,069 ms
109,628 KB
testcase_24 AC 30 ms
10,236 KB
testcase_25 AC 525 ms
47,800 KB
testcase_26 AC 1,923 ms
141,128 KB
testcase_27 AC 464 ms
48,136 KB
testcase_28 AC 18 ms
6,676 KB
testcase_29 AC 167 ms
22,304 KB
testcase_30 AC 514 ms
74,536 KB
testcase_31 AC 990 ms
95,464 KB
testcase_32 AC 664 ms
100,440 KB
testcase_33 AC 1,108 ms
112,336 KB
testcase_34 AC 1,334 ms
128,556 KB
testcase_35 AC 866 ms
101,376 KB
testcase_36 TLE -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

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) {
		FOR(j,W[3].size()) {
			R[i].insert(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];
			R[i].insert(a);
		}
	}
	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;
			}
			else {
				R[x].erase(R[x].find(a));
			}
		}
		while(L[x].size()<K-i) {
			ll a=*R[x].rbegin();
			S[x]+=a;
			R[x].erase(R[x].find(a));
			L[x].insert(a);
		}
		while(L[x].size()>K-i) {
			ll a=*L[x].begin();
			S[x]-=a;
			L[x].erase(L[x].begin());
			R[x].insert(a);
		}
		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