結果
問題 | No.2617 容量3のナップザック |
ユーザー |
|
提出日時 | 2024-01-26 22:17:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,561 bytes |
コンパイル時間 | 1,906 ms |
コンパイル使用メモリ | 170,516 KB |
実行使用メモリ | 42,752 KB |
最終ジャッジ日時 | 2024-09-28 08:21:17 |
合計ジャッジ時間 | 5,336 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 WA * 23 |
ソースコード
// Problem: No.2617 容量3のナップザック// Contest: yukicoder// URL: https://yukicoder.me/problems/no/2617// Memory Limit: 512 MB// Time Limit: 2000 ms#include<bits/stdc++.h>#define debug(x) cerr<<(#x)<<" "<<(x)<<endltypedef long long ll;typedef long double ld;typedef unsigned long long ull;#define pii pair<ll,ll>#define rep(i,a,b) for(ll i=(a);i<=(b);++i)#define per(i,a,b) for(ll i=(a);i>=(b);--i)using namespace std;bool Mbe;ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}void write(ll x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');}const ll N=2e6+9;ll n,k,seed,A,B,m,v[N],f[N],w[N],b1[N],b2[N],b3[N],t1,t2,t3,p1,p2,c,sum,ans;void add(){ll v1=b1[p1+1]+b2[p2+1];ll v2=b1[p1+1]+b1[p1+2]+b1[p1+3];if(v1==0&&v2==0)return;if(v1>v2)sum+=v1,p1++,p2++;else sum+=v2,p1+=3;}bool Med;int main(){cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";n=read(),k=read(),seed=read(),A=read(),B=read(),m=read();f[1]=seed;rep(i,2,2*n)f[i]=(A*f[i-1]+B)%m;rep(i,1,n){w[i]=f[i]%3+1;v[i]=f[i+n]*w[i];if(w[i]==1)b1[++t1]=v[i];else if(w[i]==2)b2[++t2]=v[i];else b3[++t3]=v[i];}sort(b1+1,b1+t1+1);sort(b2+1,b2+t2+1);sort(b3+1,b3+t3+1);reverse(b1+1,b1+t1+1);reverse(b2+1,b2+t2+1);reverse(b3+1,b3+t3+1);rep(i,1,min(t3,k))sum+=b3[i];rep(i,1,k-min(t3,k))add();ans=sum;per(i,min(k-1,t3-1),0){sum-=b3[i+1];add();ans=max(ans,sum);}write(ans);return 0;}