이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MB = 42;
const int MN = 2020;
const int NN = 102;
const int INF = 1e9;
ll pr[MN];
ll da[MN];
ll db[NN][NN];
ll n,a,b;
bool dpa(ll bm) {
fill(begin(da),end(da),INF);
da[0] = 0;
for(int i=0;i<n;i++) {
if(da[i] >= b) {continue;}
for(int j=i+1;j<=n;j++) {
ll wal = pr[j]-pr[i];
if((wal&bm) == wal) {
da[j] = min(da[j],da[i]+1);
}
}
}
return (da[n] <= b);
}
bool dpb(ll bm) {
memset(db,0,sizeof(db));
db[0][0] = 1;
for(int i=0;i<n;i++) {
for(int j=0;j<b;j++) {
if(!db[i][j]) {
continue;
}
for(int k=i+1;k<=n;k++) {
ll wal = pr[k]-pr[i];
if((wal&bm) == wal) {
db[k][j+1] = 1;
}
}
}
}
for(int i=a;i<=b;i++) {
if(db[n][i]) {return true;}
}
return false;
}
int main() {
cin >> n >> a >> b;
pr[0] = 0;
for(int i=0;i<n;i++) {
ll t;
cin >> t;
pr[i+1] = pr[i]+t;
}
ll res = (1LL<<MB)-1;
for(int ba=MB-1;ba>=0;ba--) {
bool bop;
if(a > 1) {
bop = dpb(res^(1LL<<ba));
} else {
bop = dpa(res^(1LL<<ba));
}
//cout << "bop it " << res << '\n';
if(bop) {res ^= (1LL<<ba);}
}
cout << res << '\n';
}
# | 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... |