Submission #681299

#TimeUsernameProblemLanguageResultExecution timeMemory
681299dxz05Bali Sculptures (APIO15_sculpture)C++14
100 / 100
105 ms472 KiB
#include <bits/stdc++.h> #include "stdio.h" using namespace std; #define SZ(s) ((int)s.size()) #define all(x) (x).begin(), (x).end() #define lla(x) (x).rbegin(), (x).rend() #define bpc(x) __builtin_popcount(x) #define bpcll(x) __builtin_popcountll(x) #define MP make_pair #define endl '\n' mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef long long ll; const int MOD = 1e9 + 7; const int N = 1e6 + 3e2; int n, A, B; int a[N]; bool check1(ll val){ vector<vector<bool>> dp(n, vector<bool>(B + 1, false)); ll sum = 0; for (int i = 0; i < n; i++){ sum += a[i]; if ((sum | val) == val) dp[i][1] = true; } for (int k = 1; k < B; k++){ for (int i = 0; i < n; i++){ sum = 0; for (int j = i + 1; j < n; j++){ sum += a[j]; if ((sum | val) == val){ dp[j][k + 1] = (dp[j][k + 1] || dp[i][k]); } } } } bool res = false; for (int i = A; i <= B; i++){ res = (res || dp[n - 1][i]); } return res; } bool check2(ll val){ vector<int> dp(n, 1e9); for (int i = 0; i < n; i++){ ll sum = 0; for (int j = i; j >= 0; j--){ sum += a[j]; if ((sum | val) == val){ dp[i] = min(dp[i], (j == 0 ? 0 : dp[j - 1]) + 1); } } } return dp.back() <= B; } void solve(){ cin >> n >> A >> B; for (int i = 0; i < n; i++) cin >> a[i]; ll mask = (1ll << 45) - 1; for (int i = 44; i >= 0; i--){ mask ^= (1ll << i); bool res = (A != 1 ? check1(mask) : check2(mask)); if (!res) mask |= (1ll << i); } cout << mask << endl; } int main(){ clock_t startTime = clock(); ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif int test_cases = 1; // cin >> test_cases; for (int test = 1; test <= test_cases; test++){ // cout << (solve() ? "YES" : "NO") << endl; solve(); } cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl; 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...