Submission #1029684

#TimeUsernameProblemLanguageResultExecution timeMemory
1029684FatonimBigger segments (IZhO19_segments)C++17
100 / 100
127 ms49236 KiB
// "We create our own demons" #include <bits/stdc++.h> using namespace std; #ifdef ONPC #include "debug.h" #else #define dbg(...) #endif #define int long long #define ll long long #define ld long double #define pi pair<int, int> // vector #define sz(a) (int)((a).size()) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define maxel(x) (*max_element(all(x))) #define minel(x) (*min_element(all(x))) #define maxpos(x) (max_element(all(x)) - x.begin()) #define minpos(x) (min_element(all(x)) - x.begin()) #define rev(x) (reverse(all(x))) // bits #define popcount(n) __builtin_popcountll(n) #define clz(n) __builtin_clzll(n) // math #define sqr(n) ((n) * (n)) #define divup(a, b) (((a) + (b)-1) / (b)) // ostream #define Fixed(a) cout << fixed << setprecision(12) << a; template <class T> bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool chmax(T& a, const T& b) { return b > a ? a = b, 1 : 0; } template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> using max_queue = priority_queue<T, vector<T>, less<T>>; template <class T> using V = vector<T>; using vi = V<int>; using vd = V<ld>; using vb = V<bool>; using vpi = V<pi>; using vvi = V<vi>; using vvb = V<vb>; const int mod = 1e9 + 7; // 998244353 1e9 + 7 const ll inf = (int)(1e18) + 7; const int inf_s = 1e9 + 7; const ld eps = 1e-9; const int B = 32; const int N = 1000 + 3; const int logn = 20; const int maxn = 5e5 + 7; /////////////////////////solve///////////////////////// void solve() { int n; cin >> n; vi a(n + 1), p(n + 1, 0); for (int i = 1; i <= n; ++i) { cin >> a[i]; p[i] = p[i - 1] + a[i]; } vpi dp(n + 1); int sum = 0; set <pi> s; pi mx = {0, 0}; for (int i = 1; i <= n; ++i) { sum += a[i]; while (!s.empty() && sum >= s.begin()->first) { int j = s.begin()->second; s.erase(s.begin()); chmax(mx, {dp[j].first, j}); } int j = mx.second; dp[i] = {mx.first + 1, p[i] - p[j]}; s.insert({dp[i].second + sum, i}); dbg(dp[i], mx); } cout << dp[n].first << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef ONPC freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif int t = 1; //cin >> t; for (int i = 1; i <= t; ++i) { #ifdef ONPC cerr << "===========" << i << "===========" << '\n'; #endif solve(); } #ifdef ONPC cerr << endl << "Time " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; #endif }
#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...