이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int Nmax = 5e5 + 10;
int n;
long long s[Nmax];
vector <int> cands[Nmax];
int f[Nmax];
pair <int, int> best;
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
s[i] += s[i - 1];
}
memset(f, -1, sizeof(f));
f[0] = 0;
cands[1].push_back(0);
for (int i = 1; i <= n; ++i) {
for (auto j: cands[i]) best = max(best, {f[j] + 1, j});
f[i] = best.first;
int t = lower_bound(s + 1, s + n + 1, s[i] * 2 - s[best.second]) - s;
cands[t].push_back(i);
}
cout << f[n];
}
# | 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... |