Submission #168671

#TimeUsernameProblemLanguageResultExecution timeMemory
168671MilkiBali Sculptures (APIO15_sculpture)C++14
100 / 100
346 ms32064 KiB
#include<bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i < b; ++i) #define REP(i, n) FOR(i, 0, n) #define _ << " " << #define sz(x) ((int) x.size()) #define pb(x) push_back(x) #define TRACE(x) cerr << #x << " = " << x << endl typedef long long ll; typedef pair<int, int> point; const int mod = 1e9 + 7; int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;} int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;} int mul(int x, int y) {return (ll) x * y % mod;} const int MAXN = 2e3 + 5; ll n, a, b, x[MAXN], prefix[MAXN], dp1[MAXN], dp[MAXN][MAXN]; int rek(int pos, int num, ll forbidden){ if(pos < 0){ if(num >= a && num <= b) return 1; else return 0; } if(dp[pos][num] != -1) return dp[pos][num]; int ret = 0; ll sum = 0; for(int i = pos; i >= 0; --i){ sum += x[i]; if((sum & forbidden) == 0) ret |= rek(i - 1, num + 1, forbidden); if(ret) return dp[pos][num] = ret; } return dp[pos][num] = ret; } int rek_min(int pos, ll forbidden){ if(pos < 0) return 0; if(dp1[pos] != -1) return dp1[pos]; int ret = 1e5; ll sum = 0; for(int i = pos; i >= 0; --i){ sum += x[i]; if((sum & forbidden) == 0) ret = min(ret, rek_min(i - 1, forbidden) + 1); } return dp1[pos] = ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> a >> b; REP(i, n) cin >> x[i]; ll forbidden = 0, sol = 0; for(int i = 40; i >= 0; --i){ memset(dp1, -1, sizeof(dp1)); memset(dp, -1, sizeof(dp)); forbidden |= (1LL << i); if(n <= 100){ if(!rek(n - 1, 0, forbidden)){ forbidden ^= (1LL << i); sol |= (1LL << i); } } else{ int val = rek_min(n - 1, forbidden); if(val > b){ forbidden ^= (1LL << i); sol |= (1LL << i); } } } cout << sol; }
#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...