Submission #370422

#TimeUsernameProblemLanguageResultExecution timeMemory
370422casperwangBigger segments (IZhO19_segments)C++14
37 / 100
1572 ms3212 KiB
#include <bits/stdc++.h> #define int long long #define pii pair<int,int> #define ff first #define ss second using namespace std; #define debug(args...) kout("[ " + string(#args) + " ]", args) void kout() { cerr << endl; } template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); } template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; } const int MAXN = 500000; int n; int a[MAXN+1]; int pre[MAXN+1]; pii dp[MAXN+1]; int ans; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], pre[i] = pre[i-1] + a[i]; dp[1] = pii(1, a[1]); for (int i = 2; i <= n; i++) { for (int j = i-1; j >= 0; j--) { if (pre[i] - pre[j] >= dp[j].ss) { dp[i] = pii(dp[j].ff + 1, pre[i] - pre[j]); break; } } } cout << dp[n].ff << '\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...