이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define stop system("pause")
#define INP freopen("balance.in","r",stdin)
#define OUTP freopen("balance.out","w",stdout)
#define int long long
using namespace std;
int n, a, b;
vector<int> v;
int dp[2001];
bool eq(int x, int mask){
//cout << "qwe " << x << ' ' << mask << ' ' << (x & mask) << endl;
return (x & mask) == 0;
}
bool bit(int x, int need){
return x & (1ll << need);
}
bool check1(int mask, int dig){
for(int i = 0; i < n;i++){
dp[i] = -1;
int mnres = INT_MAX;
int sum = 0;
for(int j = i; j >= 0;j--){
sum+=v[j];
if(eq(sum, mask) && !bit(sum, dig)){
if(i == 0)mnres = 1;
else{
if(dp[j - 1] == -1)continue;
mnres = min(mnres, dp[j - 1] + 1);
}
}
}
if(mnres!=INT_MAX){
dp[i] = mnres;
}
}
if(dp[n - 1] == -1){
return 0;
}
if(dp[n - 1] > b)return 0;
return 1;
}
main(){
ios_base::sync_with_stdio(0);
cin >> n >> a >> b;
for(int i = 0; i < n;i++){
int x; cin >> x;
v.push_back(x);
}
int mask = 0;
int ans = 0;
//cout << "che " << (1 << 30) << endl;
for(int b = 50; b >= 0;b--){
mask^=(1ll << b);
if(!check1(mask, b)){
//cout << "bad " << endl;
ans+=(1ll << b);
mask^=(1ll << b);
}
}
cout << ans;
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
컴파일 시 표준 에러 (stderr) 메시지
sculpture.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main(){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |