# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
952573 | dilanyan | Bigger segments (IZhO19_segments) | C++17 | 9 ms | 600 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.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------Kargpefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
void KarginSet(string name = "") {
ios_base::sync_with_stdio(false); cin.tie(NULL);
if (name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e15;
//-------------------KarginCode-----------------------\\
const int N = 5005, M = 1000005;
ll a[N];
pair<ll,int> dp[N];
void KarginSolve() {
int n; cin >> n;
if (n <= 5000) {
for (int i = 1;i <= n;i++) cin >> a[i];
dp[1] = { a[1],1 };
for (int i = 2;i <= n;i++) {
ll sum = a[i];
for (int j = i - 1;j >= 1;j--) {
if (dp[j].second > dp[i].second) {
dp[i].first = dp[j].first + sum;
dp[i].second = dp[j].second;
}
else if (dp[j].second == dp[i].second) {
dp[i].first = min(dp[i].first, dp[j].first + sum);
}
if (sum >= dp[j].first) {
if (dp[j].second + 1 > dp[i].second) {
dp[i].second = dp[j].second + 1;
dp[i].first = sum;
}
else if (dp[j].second + 1 == dp[i].second) {
dp[i].first = min(dp[i].first, sum);
}
}
sum += a[j];
}
}
cout << dp[n].second << '\n';
}
}
int main() {
KarginSet();
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
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... |