Submission #701495

#TimeUsernameProblemLanguageResultExecution timeMemory
701495Sanzhar23Bali Sculptures (APIO15_sculpture)C++14
100 / 100
83 ms832 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define bug cout << "bug" << endl #define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define all(x) x.begin(), x.end() #define F first #define S second #define pll pair <ll, ll> #define pii pair <int, int> #define triple pair <pair <ll, ll> , ll> #define ull unsigned long long #define ld long double #define pinode pair <node*, node*> const ll INF = 9e18 + 5; const ll inf = 1e9 + 5; const ll N = 2e3 + 5; const ll shift = 2e6; const ll mod = 998244353; const ll mod2 = 1e9 + 9; const ll M = 1e3 + 5; const ll LOG = 21; const ll sp = 263; const ll sp2 = 9973; const int block = 100; const double eps = 1e-10; ll n, a, b, Y[N], pref[N], max_value, ans = INF, mxY = 0, dp[N][N]; int dp2[2005]; int main(){ speed; cin >> n >> a >> b; for(int i = 1; i <= n; i++){ cin >> Y[i]; pref[i] = pref[i - 1] + Y[i]; } ll current_bit_prefix = 0; if(a == 1){ for(ll bit = 41; bit >= 0; bit--){ for(int i = 0; i <= n; i++){ dp2[i] = inf; } dp2[0] = 0; for(int i = 1; i <= n; i++){ for(int j = 0; j < i; j++){ ll sum = pref[i] - pref[j]; // if(((sum >> (bit + 1)) & ((current_bit_prefix >> (bit + 1)) ^ (sum >> (bit + 1)))) != 0) // continue; if((sum | (current_bit_prefix + (1ll << bit) - 1ll)) == current_bit_prefix + (1ll << bit) - 1ll) dp2[i] = min(dp2[i], dp2[j] + 1); } } if(dp2[n] <= b){ continue; }else{ current_bit_prefix ^= (1ll << bit); } } cout << current_bit_prefix << endl; return 0; } for(ll bit = 41; bit >= 0; bit--){ for(int i = 0; i <= n; i++){ for(int j = 0; j <= n; j++){ dp[i][j] = 0; } } dp[0][0] = 1; for(int i = 1; i <= n; i++){ for(int part = 0; part < n; part++){ for(int j = 0; j < i; j++){ ll sum = pref[i] - pref[j]; if(dp[j][part] == 0) continue; if((sum | (current_bit_prefix + (1ll << bit) - 1ll)) == current_bit_prefix + (1ll << bit) - 1ll) dp[i][part + 1] = 1; } // if(bit == 0) // cout << i << " " << part + 1 << " " << dp[i][part + 1] << endl; } } // return 0; int fl = 0; for(int part = a; part <= b; part++){ if(dp[n][part]){ fl = 1; break; } } // cout << "F " << bit << " " << fl << endl; if(fl) continue; current_bit_prefix ^= (1ll << bit); } cout << current_bit_prefix << endl; } /* %I64d6 6 1 3 8 1 2 1 5 4 5 4 4 3 5 6 6 2 ANS = 14 OUTPUT = 15 %I64d */
#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...