This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
#ifndef ONLINE_JUDGE
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#else
#define er(args ...) 0
#endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 3e4 + 5, maxn2 = 100 + 2, sq = 2000, lg = 31, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}
int n;
int prf[maxn], a, b;
bool chk(int l, int r, int k){
return ((prf[r] - prf[l-1])>>k&1)^1;
}
void slv1(){
vector<vector<bool>> can(n + 1, vector<bool>(n + 1, true));
vector<int> dp(n + 1, 1), dp2(n + 1);
int ans = 0;
per(k,lg-1,0){
per(i,n,1){
dp2[i] = inf;
rep(j,i,n+1){
if(can[i][j] && chk(i, j, k)){
dp2[i] = min(dp2[i], j == n? 1: dp2[j + 1] + 1);
}
}
}
if(dp2[1] <= b){
dp = dp2;
rep(i,1,n+1) rep(j,i,n+1) can[i][j] = can[i][j]&chk(i, j, k);
} else ans ^= 1<<k;
}
cout << ans << '\n';
}
void slv2(){
vector<bitset<maxn2>> dp(n + 1), dp2(n + 1);
vector<vector<bool>> can(n + 1, vector<bool>(n + 1, true));
int ans = 0;
per(k,lg-1,0){
per(i,n,1){
dp2[i].reset();
rep(j,i,n+1){
if(can[i][j] && chk(i, j, k)){
if(j == n) dp2[i][1] = true;
else dp2[i] |= dp2[j+1]<<1;
}
}
}
bool ok = false;
rep(i,a,b+1) ok |= dp2[1][i];
if(ok){
dp = dp2;
rep(i,1,n+1) rep(j,i,n+1) can[i][j] = can[i][j]&chk(i, j, k);
} else ans ^= 1<<k;
}
cout << ans << '\n';
}
int main(){ IOS();
cin >> n >> a >> b;
rep(i,1,n + 1){
cin >> prf[i];
prf[i] += prf[i-1];
}
if(a == 1) slv1();
else slv2();
return 0-0;
}
# | 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... |