結果

問題 No.2617 容量3のナップザック
ユーザー 👑 kmjpkmjp
提出日時 2024-01-27 00:50:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,858 bytes
コンパイル時間 2,647 ms
コンパイル使用メモリ 215,420 KB
実行使用メモリ 202,428 KB
最終ジャッジ日時 2024-01-27 00:50:57
合計ジャッジ時間 22,528 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 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 WA -
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 774 ms
84,652 KB
testcase_13 WA -
testcase_14 AC 727 ms
78,320 KB
testcase_15 AC 299 ms
48,848 KB
testcase_16 AC 1,161 ms
108,384 KB
testcase_17 AC 543 ms
58,868 KB
testcase_18 WA -
testcase_19 AC 55 ms
11,772 KB
testcase_20 WA -
testcase_21 AC 334 ms
43,972 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 440 ms
47,928 KB
testcase_26 AC 1,264 ms
115,016 KB
testcase_27 AC 272 ms
34,312 KB
testcase_28 AC 14 ms
6,548 KB
testcase_29 AC 141 ms
22,432 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 399 ms
79,064 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 TLE -
testcase_37 AC 835 ms
86,100 KB
testcase_38 WA -
testcase_39 AC 829 ms
81,996 KB
testcase_40 WA -
testcase_41 AC 1,228 ms
172,396 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) {
		FOR(j,W[3].size()) {
			R[i].insert(W[3][j]);
		}
		FOR(j,max(3LL,K+1-(int)W[3].size())) {
			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,min((int)K,(int)W[2].size())+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=*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());
		}
		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