답안 #996237

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996237 2024-06-10T09:07:24 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];
				}
			}
		}
	}
	int ans=0;
	for(int i=a;i<=b;i++) ans|=(dp[n][i]);
	return ans;
}
/*
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<<35)-1;
	for(int i=35;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:58:12: warning: left shift count >= width of type [-Wshift-count-overflow]
   58 |  int ans=(1<<35)-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);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -