Submission #707987

#TimeUsernameProblemLanguageResultExecution timeMemory
707987arcaneBigger segments (IZhO19_segments)C++17
37 / 100
1567 ms3020 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define mp make_pair #define pb emplace_back int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, ans = 0, tot, pos; cin >> n; int arr[n], smol[n], pref[n + 1]; for (int i = 0; i < n; i++) cin >> arr[i]; pref[0] = 0; for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + arr[i]; for (int i = 0; i < n; i++){ smol[i] = pref[i + 1]; for (int j = i - 1; j >= 0; j--){ if (pref[i + 1] - pref[j + 1] >= smol[j]) smol[i] = min(smol[i], pref[i + 1] - pref[j + 1]); } } tot = pref[n] - smol[n - 1]; pos = n - 1; ans = 1; while (tot){ while (pref[pos + 1] != tot){ pos--; //cerr << pos << '\n'; } tot -= smol[pos]; ans += 1; } cout << ans << '\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...