이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define iset indexed_set
#define ll long long int
#define ull unsigned long long int
#define f first
#define sec second
#define rep(i, st, end) for(ll i = st; i < end; i++)
const ll mod = 1e9 + 7;
using ii = pair<ll,ll>;
void solve()
{
ll n; cin>>n;
ll a[n];
rep(i,0,n) {
cin>>a[i];
}
vector<ll> dp(n), pre(n), last(n);
rep(i,0,n) {
pre[i] = a[i];
if(i) {
pre[i] += pre[i-1];
}
dp[i] = 1;
last[i] = pre[i];
}
rep(i,1,n) {
ll low = 0, high = i-1, ans = -1;
while(high >= low) {
ll mid = (high + low)/2;
if(pre[mid]+last[mid] <= pre[i]) {
ans = mid;
low = mid+1;
}
else {
high = mid-1;
}
}
if(ans != -1) {
dp[i] = dp[ans] + 1;
last[i] = pre[i] - pre[ans];
}
}
cout<<dp[n-1];
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//int t; cin>>t; while(t--)
solve();
return 0;
}
# | 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... |