이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, a, b;
bool moze[105][105];
ll niz[2005];
ll mn[2005];
bool check(ll k){
if(a > 1){
moze[0][0] = 1;
for(ll i=1; i<=100; i++){
for(ll j=0; j<=100; j++){
moze[i][j] = 0;
}
}
for(ll i=1; i<=n; i++){
ll sum = 0;
for(ll j=i; j>=1; j--){
sum += niz[j];
if((sum | k) == k){
for(ll turns=1; turns<=b; turns++){
moze[i][turns] |= moze[j-1][turns-1];
}
}
}
}
for(ll i=a; i<=b; i++) if(moze[n][i]) return 1;
return 0;
}
for(ll i=1; i<=n; i++){
mn[i] = b+5;
}
for(ll i=1; i<=n; i++){
ll sum = 0;
for(ll j=i; j>=1; j--){
sum += niz[j];
if((sum | k) == k){
mn[i] = min(mn[i], mn[j-1]+1);
}
}
}
return mn[n] <= b;
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
cin >> n >> a >> b;
for(ll i=1; i<=n; i++){
cin >> niz[i];
}
ll res = 0;
for(ll j=30; j>=0; j--){
if(!check(res+(1<<j)-1)) res += (1<<j);
}
cout << res;
return 0;
}
/*
6 1 1
8 1 2 1 5 4
*/
# | 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... |