| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 685383 | OrazB | Bigger segments (IZhO19_segments) | C++14 | 1570 ms | 3312 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 500005
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
using namespace std;
int a[N], mx, n, c[N];
ll dp[N][5];
void bit(int x){
if (x == n+1){
ll sum = 0;
vector<ll> vec;
for (int i = 1; i <= n; i++){
if (c[i]){
vec.pb(sum);
sum = 0;
}
sum += a[i];
}
vec.pb(sum);
bool tr = 0;
for (int i = 1; i < vec.size(); i++){
if (vec[i] < vec[i-1]) tr = 1;
}
if (!tr) mx = max(mx, (int)vec.size());
return;
}
for (int i = 0; i < 2; i++){
c[x] = i;
bit(x+1);
}
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
if (n <= 20){
bit(2);
return cout << mx, 0;
}
dp[1][1] = 1;
dp[1][2] = a[1];
for (int i = 2; i <= n; i++){
ll sum = 0;
for (int j = i; j > 1; j--){
sum += a[j];
if (dp[j-1][2] <= sum){
dp[i][1] = dp[j-1][1]+1;
dp[i][2] = sum;
break;
}
}
if (!dp[i][1]){
dp[i][1] = 1;
dp[i][2] = sum+a[1];
}
}
cout << dp[n][1];
}
Compilation message (stderr)
| # | 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... | ||||
