Submission #332958

#TimeUsernameProblemLanguageResultExecution timeMemory
332958CantfindmeBali Sculptures (APIO15_sculpture)C++17
37 / 100
727 ms620 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int> pi; #define f first #define s second #define FAST ios_base::sync_with_stdio(0); cin.tie(0); const int maxb = 50; const int maxn = 2010; int n,A,B; int pref[maxn]; int aa[maxn]; int dp1[110][110]; int dp2[2010]; int curbm; int cap(int x, int groups) { if (dp1[x][groups] != -1) return dp1[x][groups]; if (groups > B) return 0; if (x == n) { if (groups >= A and groups <= B) return 1; else return 0; } int res = 0; for (int i = x; i < n;i++) { int sum = pref[i] - (x == 0?0: pref[x - 1]); bool works = true; for (int b = 0; b < maxb and works; b++) { if (sum & (1 << b) and !(curbm & (1 << b))) works = false; } if (works) res = max(res, cap(i+1,groups+1)); } return dp1[x][groups] = res; } int32_t main() { cin >> n >> A >> B; for (int i =0;i<n;i++) cin >> aa[i]; for (int i =0;i<n;i++) { pref[i] = (i==0?0:pref[i-1]) + aa[i]; } int ans = (1ll << maxb)-1; if (n <= 100) { //a can be > 1 //Greedy for (int b = maxb-1; b >= 0; b--) { curbm = ans ^ (1ll << b); //cout << "HI: " << b << " " << curbm << "\n"; memset(dp1,-1,sizeof dp1); if (cap(0,0)) ans = curbm; //If you can limit all groups to have bm that doesn't have (1<<b) then ans can also not have (1<<b) //cout << "NEW: " << curbm << " " << ans << "\n\n"; } } else { //a can only be = 1; } cout << ans; }
#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...