제출 #1160254

#제출 시각아이디문제언어결과실행 시간메모리
1160254terrifierBigger segments (IZhO19_segments)C++20
13 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define niga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define F first
#define S second
#define sz() size()
#define pb push_back
#define pf push_front
#define all(a) a.begin(), a.end()
#define bll(a) a.rbegin(), a.rend();
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
/*
  a u t h o r (a b a);

──▒▒▒▒▒────▒▒▒▒▒────▒▒▒▒▒────▄████▄─────
─▒─▄▒─▄▒──▒─▄▒─▄▒──▒─▄▒─▄▒──███▄█▀───────
─▒▒▒▒▒▒▒──▒▒▒▒▒▒▒──▒▒▒▒▒▒▒─▐████─────────
─▒▒▒▒▒▒▒──▒▒▒▒▒▒▒──▒▒▒▒▒▒▒──█████▄───────
─▒─▒─▒─▒──▒─▒─▒─▒──▒─▒─▒─▒───▀████▀─────

*/
const int N = 5e5 + 9, mod =  1e9 + 7;
int n, a[N], dp[N], pos[N];

void solve(){
  cin >> n;
  vector <int> pr(n + 1, 0);
  for (int i = 1; i <= n; i++){cin >> a[i];pr[i] = pr[i - 1] + a[i];}
  for (int i = 1; i <= n; i++){
    pos[i] = max(pos[i], pos[i - 1]);
    dp[i] = dp[pos[i]] + 1;
    int k = lower_bound(all(pr), 2 * pr[i] - pr[pos[i]]) - pr.begin();
    if (k < (int)pr.sz())pos[k] = max(pos[k], i);
  }
  cout << dp[n] <<"\n";
}
signed main(){
  niga;
  int aba = 1;
  // file("name");
  // cin >> aba;
  while (aba --){
    solve();
  }
return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...