이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(a) a.begin() , a.end()
#define pb push_back
#define int long long
using namespace std;
const int maxn =2e6+10 , maxq = 1e7 , sq = sqrt(1e9) , N = 1e5 , lg = 20 , mod = 1e9+7 ;
int c[maxn] , k[200][200] , dp[maxn] , a2[maxn] ;
int n , a , b;
int solve(){
int ans = a2[50] - 1 ;
for(int i = 49 ; i >= 0 ; i--){
ans ^= a2[i] ;
for(int j = 1 ; j <= n ; j++){
for(int f = 1 ; f <= n ; f++){
k[j][f] = 0;
}
}
k[0][0] = 1;
for(int j = 1 ; j <= n ; j++){
int s = 0 ;
for(int u = j ; u >= 1 ; u--){
s+=c[u] ;
if((ans&s) == s){
for(int kk = 0 ; kk <= n ; kk++){
if(k[u-1][kk] == 1){
k[j][kk+1] = 1;
}
}
}
}
}
bool ok = 0;
for(int i = a ; i <= b ; i++){
if(k[n][i]==1){
ok = 1;
}
}
if(ok ==0 ){
ans^=a2[i];
}
}
return ans ;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> a >> b ;
for(int i = 1 ; i<= n ; i++){
cin >> c[i] ;
}
a2[0] = 1;
for(int i =1 ; i <= 50 ; i++)a2[i] = a2[i-1] * 2 ;
int ans = a2[50] - 1;
if(n <= 100){
cout << solve() ;
cout << "\n";
return 0 ;
}
for(int i = 49 ; i >= 0 ; i--){
ans^=a2[i];
for(int i = 1 ; i <= n ; i++){
dp[i] = 1e9 ;
}
dp[0] = 0 ;
for(int j =1 ;j <= n ; j ++){
int s = 0 ;
for(int k1 = j ; k1 >= 1 ; k1--){
s+=c[k1];
if((ans&s) == s){
dp[j] = min(dp[j] , dp[k1-1] + 1);
}
}
}
if(dp[n] > b){
ans^=a2[i];
}
}
cout << ans << "\n";
}
/*
6 1 3
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... |