Submission #839344

#TimeUsernameProblemLanguageResultExecution timeMemory
839344popovicirobertBali Sculptures (APIO15_sculpture)C++14
100 / 100
83 ms388 KiB
#include <bits/stdc++.h> using namespace std; int main() { #ifdef HOME ifstream cin("input.in"); ofstream cout("output.out"); #endif ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, A, B; cin >> n >> A >> B; vector<int> x(n + 1); for (int i = 1; i <= n; i++) { cin >> x[i]; } vector<int> dp_min(n + 1), dp_max(n + 1); long long answer = 0; for (int bit = 40; bit >= 0; bit--) { fill(dp_min.begin(), dp_min.end(), n + 1); fill(dp_max.begin(), dp_max.end(), -(n + 1)); dp_min[0] = dp_max[0] = 0; for (int i = 1; i <= n; i++) { long long sum = 0; for (int j = i - 1; j >= 0; j--) { sum += x[j + 1]; if (((sum | answer) >> bit) == (answer >> bit)) { dp_min[i] = min(dp_min[i], dp_min[j] + 1); dp_max[i] = max(dp_max[i], dp_max[j] + 1); } } } // cerr << dp_min[n] << " " << dp_max[n] << " " << answer << " " << bit << "\n"; if (std::max(A, dp_min[n]) > std::min(B, dp_max[n])) { answer += (1LL << bit); } } cout << answer << "\n"; 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...