이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mins(i, j) (i = min(i, j))
#define fastio ios::sync_with_stdio(false);cin.tie(nullptr);
#define ln '\n'
#define nwln cout<<ln;
using namespace std;
typedef long long ll;
int N, A, B, dp[2002][2002];
ll ans = 1, pref[2002];
int go1(ll mask) {
dp[0][0] = 0;
for(int i=1; i<=N; ++i) dp[i][0] = N;
for(int i=1; i<=N; ++i) {
for(int j=0; j<i; ++j) {
if(((pref[i]-pref[j])|mask) == mask) mins(dp[i][0], (dp[j][0]+1));
}
}
return (dp[N][0] <= B);
}
int go2(ll mask) {
int res = 0;
dp[0][0] = 1;
for(int i=0; i<=N; ++i) {
for(int j=0; j<=B; ++j) dp[i][j] = 0;
}
for(int i=1; i<=N; ++i) {
for(int j=1; j<=B; ++j) {
for(int k=0; k<i; ++k) dp[i][j] |= dp[k][j-1] & (((pref[i]-pref[k])|mask) == mask);
}
}
for(int X=A; X<=B; ++X) res |= dp[N][X];
return res;
}
int main()
{
fastio
cin>>N>>A>>B, ans <<= 41, --ans;
for(int i=1; i<=N; ++i) cin>>pref[i], pref[i] += pref[i-1];
for(int i=40; i>=0; --i) {
if(A == 1 && go1(ans^(1LL<<i))) ans ^= (1LL<<i);
if(A > 1 && go2(ans^(1LL<<i))) ans ^= (1LL<<i);
}
cout<<ans<<ln;
return 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... |