Submission #996240

# Submission time Handle Problem Language Result Execution time Memory
996240 2024-06-10T09:09:25 Z Baytoro Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define pb push_back
#define int long long 
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
#define ll long long
const int N=3e4+5;
int n,a,b;
const int INF=1e12;
int y[N];
bool check(int x){
	if(a==1){
		vector<int> dp(n+1,INF);
		dp[0]=0;
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i+1;j<=n;j++){
				sum+=y[j];
				if((sum|x)==x){
					dp[j]=min(dp[j],dp[i]+1);
				}
			}
		}
		return (dp[n]<=b);
	}
	vector<vector<int> > dp(n+1,vector<int>(n+1,0));
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<b;j++){
			int sum=0;
			if(dp[i][j]){
				for(int k=i+1;k<=n;k++){
					sum+=y[k];
					if((sum|x)==x)
						dp[k][j+1]=dp[i][j];
				}
			}
		}
	}
	for(int i=a;i<=b;i++) if(dp[n][i]) return 1;
	return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
void solve(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++) cin>>y[i];
	int ans=(1<<40)-1;
	for(int i=39;i>=0;i--){
		if(check(ans-(1<<i))){
			ans-=(1<<i);
		}
	}
	cout<<ans<<endl;
}
signed main(){
	//fopn("paint");
	int t=1;//cin>>t;
	while(t--) solve();
}

Compilation message

sculpture.cpp: In function 'void solve()':
sculpture.cpp:57:12: warning: left shift count >= width of type [-Wshift-count-overflow]
   57 |  int ans=(1<<40)-1;
      |           ~^~~~
sculpture.cpp: In function 'void fopn(std::string)':
sculpture.cpp:10:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -