Submission #634691

#TimeUsernameProblemLanguageResultExecution timeMemory
634691tvladm2009Bali Sculptures (APIO15_sculpture)C++14
100 / 100
162 ms516 KiB
#include <iostream> #include <string.h> #define int long long using namespace std; const int MAX_N = 2000; int a[MAX_N + 1], subtask5[MAX_N + 1]; bool sepoate[MAX_N + 1][MAX_N + 1]; int n, xmin, xmax; bool check(int mask, int pos) { memset(sepoate[0], false, sizeof(sepoate[0])); sepoate[0][0] = true; for (int i = 1; i <= n; i++) { sepoate[i][0] = false; for (int x = 1; x <= xmax; x++) { sepoate[i][x] = false; int sum = 0; for (int j = i; j >= 1; j--) { sum += a[j]; if ((sum & ~mask) >= (1LL << pos)) { continue; } if (sepoate[j - 1][x - 1] == true) { sepoate[i][x] = true; break; } } } } bool ok = false; for (int i = xmin; i <= xmax; i++) { ok |= sepoate[n][i]; } return ok; } bool checksubtask5(int mask, int pos = 0) { subtask5[0] = 0; for (int i = 1; i <= n; i++) { subtask5[i] = (1 << 30); int sum = 0; for (int j = i; j >= 1; j--) { sum += a[j]; if ((sum & ~mask) >= (1LL << pos)) { continue; } subtask5[i] = min(subtask5[i], subtask5[j - 1] + 1); } } return subtask5[n] <= xmax; } signed main() { cin >> n >> xmin >> xmax; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (xmin == 1) { int answer = 0; for (int bit = 50; bit >= 0; bit--) { if (checksubtask5(answer, bit) == false) { answer |= (1LL << bit); } } cout << answer; } else { int answer = 0; for (int bit = 50; bit >= 0; bit--) { if (check(answer, bit) == false) { answer |= (1LL << bit); } } cout << answer; } 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...