제출 #519560

#제출 시각아이디문제언어결과실행 시간메모리
519560Dasha_GnedkoBigger segments (IZhO19_segments)C++17
27 / 100
1587 ms12356 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/detail/standard_policies.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#pragma GCC optimize("Ofast") //#pragma GCC target("avx2") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4") using namespace std; //using namespace __gnu_pbds; //template <typename T> using ordered_set = tree <T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update>; mt19937 gen(time(0)); #define ll long long #define ld long double #define pb push_back #define F first #define S second #define TIME clock() * 1.0 / CLOCKS_PER_SEC #define sz(a) int32_t(a.size()) #define endl '\n' //#define int long long const int N = 5e5 + 100; const int M = 31; const int mod = 1e9 + 7; const ll inf = 1e18 + 7; ll pref[N]; int a[N]; vector < pair < int, ll > > add[N]; set < pair < int, ll > > st; pair < int, ll > dp[N]; void upd(pair < int, ll > &a, pair < int, ll > b) { if (a.F < b.F) a = b; else if (a.F == b.F) a.S = min(a.S, b.S); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif // LOCAL int n; cin >> n; for(int i = 0; i < n; i++) { cin >> a[i]; if (i) pref[i] = pref[i - 1]; pref[i] += a[i]; } dp[0] = {1, a[0]}; for(int i = 0; i < n; i++) { dp[i] = {1, pref[i]}; for(int j = i - 1; j >= 0; j--) { upd(dp[i], {dp[j].F, dp[j].S + pref[i] - pref[j]}); if (pref[i] - pref[j] < dp[j].S) continue; for(int z = j; z < i; z++) { if (pref[i] - pref[z] < dp[j].S + pref[z] - pref[j]) break; upd(dp[i], {dp[j].F + 1, pref[i] - pref[z]}); } } } cout << dp[n - 1].F; }
#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...