제출 #979942

#제출 시각아이디문제언어결과실행 시간메모리
979942underwaterkillerwhaleCigle (COI21_cigle)C++17
100 / 100
196 ms88452 KiB
#include <bits/stdc++.h> #define se second #define fs first #define pb push_back #define ll long long #define ii pair<ll,ll> #define ld long double #define SZ(v) (int)v.size() #define ALL(v) v.begin(), v.end() #define bit(msk, i) ((msk >> i) & 1) #define iter(id, v) for(auto id : v) #define rep(i,m,n) for(int i=(m); i<=(n); i++) #define reb(i,m,n) for(int i=(m); i>=(n); i--) using namespace std; mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count()); ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); } const int N = 5e3 + 7; const ll Mod = 1e9 + 7; const int szBL = 916; const ll INF = 1e9; const int BASE = 137; int n; int a[N]; int dp[N][N], f[N]; void solution () { cin >> n; rep (i, 1, n) cin >> a[i]; rep (L, 1, n) { f[0] = -INF; rep (i, 1, L - 1) { f[i] = max(f[i - 1], dp[i][L - 1]); } int ptr = L - 1, curcost = 0, suf = a[L - 1], pre = a[L]; dp[L][L - 1] = f[L - 1]; rep (R, L, n) { dp[L][R] = max(dp[L][R], dp[L][R - 1]); while (ptr > 1 && suf < pre) { dp[L][R] = max (dp[L][R], dp[ptr - 1][L - 1] + curcost); suf += a[ptr - 1]; --ptr; } if (suf == pre) { curcost++; dp[L][R + 1] = max (dp[L][R + 1], f[ptr - 1] + curcost); } // cout << L<<","<<R<<" "<<dp[L][R] <<" "<<suf<<","<<pre<<": "<<f[ptr - 1] + curcost<<"\n"; pre += a[R + 1]; } } int res = 0; rep (L, 1, n) { res = max(res, dp[L][n]); } cout << res <<"\n"; } #define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); int main () { // file("c"); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll num_Test = 1; // cin >> num_Test; while(num_Test--) solution(); } /* 18 3 2 5 6 21 13 19 9 17 14 17 19 20 2 16 2 10 9 14 19 20 14 16 1 3 17 19 14 21 18 19 4 7 5 12 1 13 */
#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...