Submission #961466

#TimeUsernameProblemLanguageResultExecution timeMemory
961466ByeWorldCigle (COI21_cigle)C++14
48 / 100
1057 ms13584 KiB
#include <bits/stdc++.h> #include <random> #define ll long long #define int long long #define fi first #define se second #define pb push_back #define md ((l+r)>>1) #define lf (id<<1) #define rg ((id<<1)|1) #define ld long double using namespace std; typedef pair<int,int> pii; typedef pair<pii,pii> ipii; const int MAXN = 5e3+10; const int MAXA = 1e6+10; const int INF = 2e9+10; const int LOG = 30; const int MOD = 1e9+7; void chmx(int &a, int b){ a = max(a, b); } int n; int a[MAXN], pr[MAXN], dp[MAXN][MAXN]; signed main() { // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; pr[i] = pr[i-1] + a[i]; } for(int r=1; r<=n; r++){ for(int k=r-1; k>=1; k--) chmx(dp[r][r], dp[k][r-1]); for(int l=1; l<=r-1; l++){ // build dp[l][r], row atas dp[l][r] = dp[l][r-1]; int down = 0, idx = l, add = 0; for(int k=l-1; k>=1; k--){ // cek dp[k][l], row bawah chmx(dp[l][r], dp[k][l-1]+add); down += a[k]; while(idx+1<=r-1 && pr[idx]-pr[l-1] < down){ // r gk boleh dipake // atas masi kurang idx++; } if(pr[idx]-pr[l-1] == down) add++; // kena 4 } } } int ANS = 0; for(int i=1; i<=n; i++) ANS = max(ANS, dp[i][n]); cout << ANS << '\n'; // dp[l][r] selalu increasing kalo r nya increasing? // for(int l=1; l<=n; l++){ // for(int r=l; r<=n; r++) cout << dp[l][r] << "p\n"[r==n]; // } }
#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...