Submission #653974

#TimeUsernameProblemLanguageResultExecution timeMemory
653974pavementCigle (COI21_cigle)C++17
48 / 100
1099 ms102344 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif #define int long long #define mp make_pair #define mt make_tuple #define pb push_back #define ppb pop_back #define eb emplace_back #define g0(a) get<0>(a) #define g1(a) get<1>(a) #define g2(a) get<2>(a) #define g3(a) get<3>(a) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using db = double; using ll = long long; using ld = long double; using ii = pair<int, int>; using iii = tuple<int, int, int>; using iiii = tuple<int, int, int, int>; template<class key, class value = null_type, class cmp = less<key> > using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; int N, ans, d[5005], p[5005], dp[5005][5005]; struct node { node *left, *right; int S, E, val, pv; node(int _s, int _e) : S(_s), E(_e), val(0), pv(0) { if (S == E) { return; } int M = (S + E) >> 1; left = new node(S, M); right = new node(M + 1, E); } void prop() { if (S == E || !pv) return; left->val += pv; left->pv += pv; right->val += pv; right->pv += pv; pv = 0; } void clear() { val = pv = 0; if (S != E) { left->clear(); right->clear(); } } void upd(int l, int r, int v) { if (l > E || r < S) return; if (l <= S && E <= r) { val += v; pv += v; return; } prop(); left->upd(l, r, v); right->upd(l, r, v); val = max(left->val, right->val); } } *root; main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N; for (int i = 1; i <= N; i++) { cin >> d[i]; p[i] = p[i - 1] + d[i]; } root = new node(1, N); for (int j = N; j >= 1; j--) { root->clear(); for (int k = j + 1; k <= N; k++) { root->upd(k, k, dp[j + 1][k]); } for (int i = j; i >= 1; i--) { int lo = j + 1, hi = N, ans = -1; while (lo <= hi) { int mid = (lo + hi) >> 1; if (p[mid] - p[j] == p[j] - p[i - 1]) { ans = mid; break; } else if (p[mid] - p[j] > p[j] - p[i - 1]) hi = mid - 1; else lo = mid + 1; } dp[i][j] = root->val; //~ cout << "DP " << i << ' ' << j << ' ' << root->val << '\n'; if (ans != -1) { root->upd(ans + 1, N, 1); //~ cout << " + " << i << ' ' << ans << '\n'; } } } for (int i = 1; i <= N; i++) { ans = max(ans, dp[1][i]); } cout << ans << '\n'; }

Compilation message (stderr)

cigle.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   71 | main() {
      | ^~~~
#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...