이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define push_back emplace_back
#define push_front emplace_front
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 500000;
int n;
int a[MAXN+1];
int pre[MAXN+1];
int dp[MAXN+1];
int len[MAXN+1];
deque <pii> deq;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i], pre[i] = pre[i-1] + a[i];
deq.push_back(0, 0);
pii tmp;
for (int i = 1; i <= n; i++) {
while (deq.size() && pre[i]-pre[deq.front().ss] >= deq.front().ff) {
dp[i] = dp[deq.front().ss] + 1;
tmp = deq.front();
deq.pop_front();
}
deq.push_front(tmp);
while (deq.size() && deq.back().ff >= pre[i]-pre[deq.front().ss])
deq.pop_back();
deq.push_back(pre[i]-pre[deq.front().ss], i);
}
cout << dp[n] << '\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... |