제출 #549418

#제출 시각아이디문제언어결과실행 시간메모리
549418Soumya1Bali Sculptures (APIO15_sculpture)C++17
100 / 100
112 ms352 KiB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
long long ar[2001];
int n, a, b;
long long s(int i, int j) {
  return ar[j] - ar[i - 1];
}
bool solve1(long long x) {
  int dp[n + 1][n + 1];
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      for (int k = 0; k < i; k++) {
        dp[i][j] |= dp[k][j - 1] & ((s(k + 1, i) & x) == s(k + 1, i));
        if (dp[i][j]) break;
      }
    }
  }
  for (int i = a; i <= b; i++) {
    if (dp[n][i]) return true;
  }
  return false;
}
int solve2(long long x) {
  int dp[n + 1];
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i] = n + 50;
    for (int j = 0; j < i; j++) {
      if ((s(j + 1, i) & x) == s(j + 1, i)) dp[i] = min(dp[i], dp[j] + 1);
    }
  }
  return dp[n];
}
void testCase() {
  cin >> n >> a >> b;
  for (int i = 1; i <= n; i++) cin >> ar[i];
  for (int i = 1; i <= n; i++) ar[i] += ar[i - 1];
  if (a == 1) {
    long long ans = 0;
    for (int bit = 41; bit >= 0; bit--) {
      long long x = ans;
      for (int j = bit - 1; j >= 0; j--) x |= (1LL << j);
      if (solve2(x) > b) ans |= (1LL << bit);
    }
    cout << ans << "\n";
  } else {
    long long ans = 0;
    for (int bit = 41; bit >= 0; bit--) {
      long long x = ans;
      for (int j = bit - 1; j >= 0; j--) x |= (1LL << j);
      if (!solve1(x)) ans |= (1LL << bit);
    }
    cout << ans << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...