이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e3 + 5;
int n, u, v;
int a[N];
ll pre[N];
bool ck(ll a, ll b, ll c){
return (a | b) < (b | c);
}
namespace sub1{
int dp[N];
void solve(){
ll ans = 0;
for (ll i = 45; i >= 0; -- i){
ll cur = (1ll << i);
for (int j = 1; j <= n; ++ j){
dp[j] = n + 1;
for (int k = j - 1; k >= 0; -- k){
if (ck(pre[j] - pre[k], ans, cur)) dp[j] = min(dp[j], dp[k] + 1);
}
}
if (dp[n] > v) ans += cur;
}
cout << ans;
}
}
namespace sub2{
bool dp[105][105];
void solve(){
ll ans = 0;
for (ll i = 45; i >= 0; -- i){
ll cur = 1ll << i;
dp[0][0] = 1;
for (int j = 1; j <= n; ++ j){
for (int t = 0; t <= n; ++ t) dp[j][t] = 0;
for (int k = 0; k < j; ++ k){
if (ck(pre[j] - pre[k], ans, cur)){
for (int t = 0; t <= k; ++ t) dp[j][t + 1] |= dp[k][t];
}
}
}
bool ck = false;
for (int t = u; t <= v; ++ t) if (dp[n][t]) ck = true;
if (!ck) ans += cur;
}
cout << ans;
}
}
void solve(){
cin >> n >> u >> v;
for (int i = 1; i <= n; ++ i) cin >> a[i], pre[i] = pre[i - 1] + a[i];
if (u == 1) sub1::solve();
else sub2::solve();
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
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... |