Submission #699337

#TimeUsernameProblemLanguageResultExecution timeMemory
699337CatalinTBali Sculptures (APIO15_sculpture)C++17
100 / 100
86 ms340 KiB
#include <vector> #include <iostream> #include <cassert> #include <algorithm> #include <numeric> #include <iostream> #include <set> #include <map> #include <string> #include <unordered_map> #include <functional> #include <bitset> #include <sstream> using namespace std; using int64 = long long; int N, A, B; vector<int> X; int64 S; bool only_B(int64 mask, int64 care) { vector<int> dp(N + 1, (1<<30)); dp[0] = 0; for (int i = 1; i <= N; i++) { int64 cur = 0; for (int j = i; j >= 1; j--) { cur += X[j]; if (((cur & care) | mask) == mask) { if (dp[i] > dp[j-1] + 1) { dp[i] = dp[j-1] + 1; } } } } return dp[N] <= B; } bool A_B(int64 mask, int64 care) { vector<vector<char>> dp(N + 1, vector<char>(N + 1)); dp[0][0] = 1; for (int k = 1; k <= B; k++) { for (int i = 1; i <= N; i++) { int64 cur = 0; for (int j = i; j >= 1; j--) { cur += X[j]; if (((cur & care) | mask) == mask) { dp[k][i] |= dp[k-1][j-1]; } } } } for (int k = A; k <= B; k++) if (dp[k][N]) return true; return false; } bool can_do(int64 mask, int64 care) { if (A == 1) return only_B(mask, care); else return A_B(mask, care); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> A >> B; X.resize(N + 1); for (int i = 1; i <= N; i++) { cin >> X[i]; S += X[i]; } const int max_bit = 42; int64 mask = 0; int64 care = 0; for (int i = max_bit; i >= 0; i--) { int64 bit = (1LL<<i); care |= bit; if (can_do(mask, care)) { } else { mask |= bit; } } cout << mask << "\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...