# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
701647 | lto5 | Bigger segments (IZhO19_segments) | C++14 | 22 ms | 3928 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using TNode = pair<int, int64_t>;
int a[100005];
int64_t s[100005];
TNode f[100005];
int64_t get(int l, int r) {
return s[r] - s[l - 1];
}
TNode better(TNode a, TNode b) {
if (a.first != b.first) {
return a.first > b.first ? a : b;
}
return a.second < b.second ? a : b;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define task "a"
if (fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
for (int i = 0; i <= n; i++) {
f[i] = {0, 1e18};
}
f[1] = {1, a[1]};
for (int i = 1; i <= n; i++) {
if (f[i].first == 0) {
continue;
}
f[i + 1] = better(f[i + 1], {f[i].first, f[i].second + a[i + 1]});
int lo = i + 1, hi = n;
int pos = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (get(i + 1, mid) >= f[i].second) {
pos = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
if (pos != -1) {
f[pos] = better(f[pos], {f[i].first + 1, get(i + 1, pos)});
}
}
int best = 0;
for (int i = 1; i <= n; i++) {
best = max(best, f[i].first);
}
cout << best;
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... |