This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// MDSPro
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include "bits/stdc++.h"
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...) 42
#endif
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ld = long double;
const ld PI = 3.141592653589793;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll INFLL = 4e18;
const double EPS = 1e-9;
const int MAXN = 1000*1007;
void solve(int NT){
int n; cin >> n;
vector<int> a(n); for(int i = 0; i < n; ++i) cin >> a[i];
int ans;
vector dp(n+1,INFLL); dp[0] = 0;
vector opt(n+1,1);
for(int i = 1; i <= n; ++i){
vector old = dp;
vector best = opt;
dp.assign(n+1,INFLL); opt.assign(n+1,n-1);
debug(old);
for(int j = n; j >= 1; --j){
int l = best[j];
int r = (j+1 > n ? j : min(opt[j+1],j));
ll sum = 0; for(int k = j; k > r; --k) sum += a[k-1];
for(int k = r; k >= l; --k){
sum += a[k-1];
if(sum >= old[k-1] && sum < dp[j]) {
dp[j] = sum;
opt[j] = k;
}
}
debug(i,j,sum);
}
debug(dp);
debug(opt);
if(dp[n] == INFLL) break;
ans = i;
}
cout << ans;
}
// #define TESTCASES
int main() {
cin.tie(0)->sync_with_stdio(0);
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
int t = 1;
#ifdef TESTCASES
cin >> t;
#endif
for(int i = 1; i <= t; ++i){
solve(i);
cout << "\n";
}
}
Compilation message (stderr)
segments.cpp: In function 'void solve(int)':
segments.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(x...) 42
| ^~
segments.cpp:37:9: note: in expansion of macro 'debug'
37 | debug(old);
| ^~~~~
segments.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(x...) 42
| ^~
segments.cpp:50:13: note: in expansion of macro 'debug'
50 | debug(i,j,sum);
| ^~~~~
segments.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(x...) 42
| ^~
segments.cpp:52:9: note: in expansion of macro 'debug'
52 | debug(dp);
| ^~~~~
segments.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(x...) 42
| ^~
segments.cpp:53:9: note: in expansion of macro 'debug'
53 | debug(opt);
| ^~~~~
segments.cpp:58:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
58 | cout << ans;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |