제출 #84703

#제출 시각아이디문제언어결과실행 시간메모리
84703popovicirobertBali Sculptures (APIO15_sculpture)C++14
0 / 100
2 ms576 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) { if(bit == 0) { return (s | conf) == (s & conf); } return ((s | conf) >> (bit - 1)) == ((s & conf) >> (bit - 1)); } 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); } conf += (1LL << bit) - 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; } } } } conf -= (1LL << bit) - 1; bool ok = 0; for(i = a; i <= b; i++) { if(dp[n][i]) { ok = 1; } } //cerr << bit << " " << ok << "\n"; if(!ok) { conf += (1LL << bit); } } return conf; } inline ll solve2(int n, 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; } conf += (1LL << bit) - 1; vector <bool> dp(n + 1); int i, j; dp[0] = 1; for(i = 1; i <= n; i++) { ll s = 0; for(j = i - 1; j >= 0; j--) { s += arr[j + 1]; if(dp[j] && check(s, conf, bit)) { dp[i] = 1; break; } } } conf -= (1LL << bit) - 1; if(!dp[n]) { 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); } //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...