제출 #920498

#제출 시각아이디문제언어결과실행 시간메모리
920498aykhnBali Sculptures (APIO15_sculpture)C++17
100 / 100
117 ms600 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 0x3F3F3F3F const int mod = 1e9 + 7; const int MXN = 2e3 + 5; int n, A, B; int a[MXN]; int _1() { int x = 0, y = (1LL << 61) - 1; for (int b = 60; b >= 0; b--) { vector<int> dp(n + 1, inf); dp[0] = 0; x |= (1LL << b); for (int i = 1; i <= n; i++) { int s = 0; for (int j = i; j >= 1; j--) { s += a[j]; if ((s & x)) continue; dp[i] = min(dp[i], dp[j - 1] + 1); } } if (dp[n] > B) x ^= (1LL << b); } return y - x; } int _2() { int x = 0, y = (1LL << 61) - 1; for (int b = 60; b >= 0; b--) { vector<vector<int>> dp(n + 1, vector<int> (n + 1, 0)); dp[0][0] = 1; x |= (1LL << b); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { int s = 0; for (int k = j; k >= 1; k--) { s += a[k]; if ((s & x)) continue; dp[i][j] |= dp[i - 1][k - 1]; } } } int f = 0; for (int i = A; i <= B; i++) f |= dp[i][n]; if (!f) x ^= (1LL << b); } return y - x; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> A >> B; for (int i = 1; i <= n; i++) cin >> a[i]; cout << (A == 1 ? _1() : _2()) << '\n'; }
#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...