# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
171628 | davitmarg | Bigger segments (IZhO19_segments) | C++17 | 139 ms | 20968 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 500005;
int n;
LL a[N],pr[N];
pair<int, LL> dp[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%lld", a + i);
for (int i = 1; i <= n; i++)
{
dp[i] = MP(0, -mod * mod);
pr[i] = pr[i - 1] + a[i];
}
for (int i = 0; i < n; i++)
{
dp[i + 1] = max(dp[i + 1], MP(dp[i].first, dp[i].second - a[i+1]));
int l = i + 1, r = n, m, pos = 0;
while (l <= r)
{
m = (l + r) / 2;
if (pr[m] - pr[i] >= -dp[i].second)
{
r = m - 1;
pos = m;
}
else
l = m + 1;
}
dp[pos] = max(dp[pos], MP(dp[i].first + 1, pr[i] - pr[pos]));
//cout << i << " = " << dp[i].first << " : " << -dp[i].second << endl;
//cout << pos << endl << endl;
}
cout << dp[n].first << endl;
return 0;
}
/*
*/
컴파일 시 표준 에러 (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... |