Submission #1133149

#TimeUsernameProblemLanguageResultExecution timeMemory
1133149g4yuhgBali Sculptures (APIO15_sculpture)C++20
100 / 100
104 ms492 KiB
#pragma GCC optimize("O3") #pragma GCC target("avx2") #include <bits/stdc++.h> typedef long long ll; #define int long long #define endl '\n' #define yes cout<<"YES"<<endl; #define no cout<<"NO"<<endl; #define fi first #define se second #define pii pair<ll, ll> #define inf 1e18 #define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MP make_pair #define TASK "ghuy4g" #define start if(fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin);freopen(TASK".out","w",stdout);} #define LOG 46 #define N 2005 using namespace std; ll onbit(ll mask, ll i) { return mask | (1LL << i); } ll getbit(ll mask, ll i) { return (mask >> i) & 1LL; } ll gb(ll mask1, ll mask2, ll i) { return (mask1 >> i) | (mask2 >> i); } ll n, L, R; ll a[N], pf[N]; ll ans; bitset<N> dp[N]; void sub1() { for (int bit = LOG; bit >= 0; bit--) { for (int k = 0; k <= R; k++) { dp[k].reset(); } dp[0][0] = 1; bool ok = false; for (int k = 1; k <= R; k++) { for (int i = 1; i <= n; i ++) { for (int j = dp[k - 1]._Find_first(); j < i; j = dp[k - 1]._Find_next(j)) { ll xet = pf[i] - pf[j]; if (gb(xet, ans, bit) == (ans >> bit)) { dp[k].set(i); if (k >= L && i == n) { ok = true; } break; } if (ok) break; } if (ok) break; } if (ok) break; } if (!ok) { ans = onbit(ans, bit); } } cout << ans; } ll f[2005]; void sub2() { for (int bit = LOG; bit >= 0; bit --) { for (int i = 0; i < 2005; i ++) { f[i] = inf; } f[0] = 0; for (int i = 1; i <= n; i ++) { for (int j = 0; j < i ; j ++) { ll xet = pf[i] - pf[j]; if (gb(xet, ans, bit) == (ans >> bit)) { f[i] = min(f[i], 1 + f[j]); } } } bool ok = 0; if (f[n] <= R) { ok = 1; } if (!ok) { ans = onbit(ans, bit); } } cout << ans; } signed main(void) { faster; cin >> n >> L >> R; for (int i = 1; i <= n; i++) { cin >> a[i]; pf[i] = pf[i - 1] + a[i]; } if (n <= 100) { sub1(); } else { sub2(); } 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...