이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll u = 1;
int n,a,b;
ll A[2005];
int dp[2005];
bool pos(ll mask){
for(int i=1; i<=n; i++){
dp[i] = 1e8;
for(int j=0; j<i; j++){
ll w = A[i] - A[j];
if((w&mask) == w) dp[i] = min(dp[i],1 + dp[j]);
}
}
return (dp[n] <= b);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin>>n>>a>>b;
for(int i=1; i<=n; i++) cin>>A[i];
for(int i=1; i<=n; i++) A[i]+=A[i-1];
if(!A[n]){
cout<<0;
return 0;
}
if(a > 1){
assert(n<=100);
cout<<A[n];
}
else{
int last_digit = 41;
while(pos( (u<<(last_digit+1)) - 1 )) last_digit--;
last_digit++;
ll mask = (u<<last_digit)*2 - 1;
for(int i=last_digit-1; i>=0; i--){
mask^=(u<<i);
if(pos(mask)) continue;
else mask^=(u<<i);
}
cout<<mask;
}
}
# | 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... |