제출 #84706

#제출 시각아이디문제언어결과실행 시간메모리
84706popovicirobertBali Sculptures (APIO15_sculpture)C++14
100 / 100
176 ms1036 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long using namespace std; inline bool check(ll s, ll conf, int bit) { return ((s | conf) >> bit) == (conf >> bit); } inline ll solve1(int n, int a, int b, vector <int> &arr) { ll sum = 0; for(auto it : arr) { sum += it; } ll conf = 0; for(int bit = 60; bit >= 0; bit--) { if((1LL << bit) > sum) { continue; } vector < vector <bool> > dp; int i, j; dp.resize(n + 1); for(i = 0; i <= n; i++) { dp[i].resize(b + 1); } dp[0][0] = 1; for(i = 1; i <= n; i++) { for(int k = 1; k <= b; k++) { ll s = 0; for(j = i - 1; j >= 0; j--) { s += arr[j + 1]; if(dp[j][k - 1] && check(s, conf, bit)) { dp[i][k] = 1; break; } } } } bool ok = 0; for(i = a; i <= b; i++) { if(dp[n][i]) { ok = 1; } } if(!ok) { conf += (1LL << bit); } } return conf; } inline ll solve2(int n, vector <int> &arr, int b) { ll sum = 0; for(auto it : arr) { sum += it; } ll conf = 0; for(int bit = 60; bit >= 0; bit--) { if((1LL << bit) > sum) { continue; } vector < pair <bool, int> > dp(n + 1); int i, j; dp[0] = {1, 0}; for(i = 1; i <= n; i++) { ll s = 0; dp[i].second = n + 1; for(j = i - 1; j >= 0; j--) { s += arr[j + 1]; if(dp[j].first && check(s, conf, bit)) { dp[i].first = 1; dp[i].second = min(dp[i].second, dp[j].second + 1); } } } if(!dp[n].first || dp[n].second > b) { conf += (1LL << bit); } } return conf; } int main() { //ifstream cin("C.in"); //ofstream cout("C.out"); int i, n, a, b; ios::sync_with_stdio(false); cin >> n >> a >> b; vector <int> arr(n + 1); for(i = 1; i <= n; i++) { cin >> arr[i]; } if(n <= 100) { cout << solve1(n, a, b, arr); } else { cout << solve2(n, arr, b); } //cin.close(); //cout.close(); 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...