Submission #1128557

#TimeUsernameProblemLanguageResultExecution timeMemory
1128557ShaShiBali Sculptures (APIO15_sculpture)C++20
100 / 100
643 ms4384 KiB
#include <bits/stdc++.h> #define int long long // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #define F first #define S second #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define kill(x) cout << x << "\n", exit(0); #define pii pair<int, int> #define pll pair<long long, long long> #define endl "\n" using namespace std; typedef long long ll; // typedef __int128_t lll; typedef long double ld; const int MAXN = (int)2000 + 7; const int MOD = 998244353; const ll INF = (ll)1e18 + 7; const int LG = 45; int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, q, ans, x, sar, tah, flag; int arr[MAXN], ps[MAXN], A, B; bool dp[MAXN][MAXN]; int pd[MAXN]; inline void solve1() { for (int k=LG-1; k>=0; k--) { memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i=0; i<=n; i++) { for (int j=0; j<=B; j++) { if (!dp[i][j] || j == B) continue; for (int o=i+1; o<=n; o++) { if (ans - (ans|(((ps[o]-ps[i])/(1ll<<k)) * (1ll<<k))) == 0) { dp[o][j+1] = 1; } } } } flag = 0; for (int i=A; i<=B; i++) if (dp[n][i]) flag = 1; if (!flag) ans += (1ll<<k); } } inline void solve2() { for (int k=LG-1; k>=0; k--) { fill(pd, pd+n+7, n+7); pd[0] = 0; for (int i=0; i<=n; i++) { for (int j=i+1; j<=n; j++) { if (pd[j] <= pd[i]+1) continue; if (ans - (ans|(((ps[j]-ps[i])/(1ll<<k)) * (1ll<<k))) == 0) { pd[j] = pd[i]+1; } } } if (pd[n] > B) ans += (1ll<<k); } } int32_t main() { #ifdef LOCAL freopen("inp.in", "r", stdin); freopen("res.out", "w", stdout); #else ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif cin >> n >> A >> B; for (int i=1; i<=n; i++) { cin >> arr[i]; ps[i] = ps[i-1]+arr[i]; } if (A != 1) solve1(); else solve2(); cout << ans << endl; 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...