Submission #711154

#TimeUsernameProblemLanguageResultExecution timeMemory
711154ThienuBigger segments (IZhO19_segments)C++17
13 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define u_map unordered_map #define u_set unordered_set #define u_multiset unordered_multiset using ll = long long; using vvi = vector<vector<int>>; using vi = vector<int>; using vvll = vector<vector<long long>>; using vll = vector<long long>; using vd = vector<double>; using vvd = vector<vector<double>>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template<typename C> struct rge{C l, r;}; template<typename C> rge<C> range(C i, C j) { return rge<C>{i, j}; } template<typename C> ostream& operator<<(ostream &os, rge<C> &r) { os << '{'; for(auto it = r.l; it != r.r; it++) os << "," + (it == r.l) << *it; os << '}'; return os; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '{' << p.first << "," << p.second << '}'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ","; return os << '}'; } void dbg_out() { cerr << ']' << endl; } template<typename A> void dbg_out(A H) { cerr << H; dbg_out(); } template<typename A, typename B, typename... C> void dbg_out(A H, B G, C... T) { cerr << H << ","; dbg_out(G, T...); } #ifdef DEBUG #define debug(...) cerr << "[" << #__VA_ARGS__ << "] = [", dbg_out(__VA_ARGS__) #else #define debug(...) #endif void solve(){ int n; cin >> n; vll v(n); for(int i = 0; i < n; i++) cin >> v[i]; vll dp(n+1, 1e9); vll sum(n+1, 1e9); dp[0] = 0; sum[0] = 0; for(int i = 1; i <= n; i++){ int suf = 0; for(int j = i-1; j >= 0; j--){ suf += v[j]; if(suf < sum[i] && suf >= sum[j]) { assert(dp[i] >= dp[j] + 1); dp[i] = dp[j] + 1; sum[i] = suf; } } } debug(dp); debug(sum); cout << dp[n] << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#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...