Submission #953787

# Submission time Handle Problem Language Result Execution time Memory
953787 2024-03-26T16:20:09 Z PM1 Uplifting Excursion (BOI22_vault) C++17
0 / 100
13 ms 2660 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr first
#define sc second
const int mxn=305;
ll m,a[mxn*2],l,sum,ans,num;
vector<pair<ll,ll>>v;
ll dp[2][mxn*mxn*2];
void add(ll tedad,ll x,ll z){
	tedad=(min(tedad,m));
	for(ll i=1;i<=tedad;){
		v.push_back({i*x,z*i});
		tedad-=i;
	}
	if(tedad>0)
		v.push_back({tedad*x,z*tedad});
}
void solve(){
	for(ll i=m;i<2*m+1;i++){
		ans+=a[i];
		num+=a[i]*(i-m);
		add(a[i],-(i-m),-1);
	}
	ll i=m-1;
	for(;i>=0;i--){
		if(num+a[i]*(i-m)>=l){
			ans+=a[i];
			num+=a[i]*(i-m);
			add(a[i],-(i-m),-1);
			continue;
		}
		ll x=num-l;
		x=x/(i-m);
		num+=a[i]*x;
		ans+=x;
		add(x,-(i-m),-1);
		add(a[i]-x,i-m,1);
		break;
	}
	for(;i>=0;i--){
		add(a[i],(i-m),1);
	}
}
void solve1(){
	for(ll i=m;i>=0;i--){
		ans+=a[i];
		num+=a[i]*(i-m);
		add(a[i],(i-m),-1);
	}
	ll i=m+1;
	for(;i<m*2+1;i++){
		if(num+a[i]*(i-m)<=l){
			ans+=a[i];
			num+=a[i]*(i-m);
			add(a[i],(i-m),-1);
			continue;
		}
		ll x=l-num;
		x=x/(i-m);
		num+=(i-m)*x;
		ans+=x;
		add(x,(i-m),-1);
		add(a[i]-x,i-m,1);
		break;
	}
	for(;i<m*2+1;i++){
		add(a[i],(i-m),1);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>m>>l;
	for(ll i=0;i<m*2+1;i++){
		cin>>a[i];
		sum+=(i-m)*a[i];
	}
	if(sum<=l)
		solve();
	else
		solve1();

	for(int i=0;i<=2*m*m;i++)dp[1][i]=-1e18;
	dp[1][m*m]=0;
	for(int i=0;i<v.size();i++){
		ll x=v[i].fr,y=v[i].sc;
		int z=i&1;
		for(ll j=0;j<=2*m*m;j++){
			if(j-x>=0 && j-x<=2*m*m)
				dp[z][j]=max(dp[z^1][j],dp[z^1][j-x]+y);
			else
				dp[z][j]=dp[z^1][j];
		}
	}
	int x=v.size()&1;
	x^=1;
	if(dp[x][l-num+m*m]<-m){
		cout<<"impossible";
		return 0;
	}
	
	cout<<ans+dp[x][l-num+m*m];
	return 0;
}

Compilation message

vault.cpp: In function 'int main()':
vault.cpp:87:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 13 ms 2660 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 13 ms 2660 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 13 ms 2660 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 13 ms 2660 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 13 ms 2660 KB Output isn't correct
6 Halted 0 ms 0 KB -