제출 #1321294

#제출 시각아이디문제언어결과실행 시간메모리
1321294ayazBigger segments (IZhO19_segments)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define line() "author : AyazN";
#endif

#define all(x) (x).begin(), (x).end()
#define isz(x) (int)(x.size())
#define int ll

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int sz = 200500, inf = 1000000000, LOG = 20;
const ll mod = 1000000007, INF = 1000000000000000000;

void run_case(int tc) {
  int n; cin >> n;
  vector<int> a(n + 1), p(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = p[i - 1] + a[i];
  }
  int ans = 0;
  vector<pair<int, int>> dp[n + 1];
  for (int i = 1; i <= n; i++) {
    dp[i].push_back({1, p[i]});
    for (auto &[cnt, sum] : dp[i]) {
      auto it = lower_bound(p.begin() + i + 1, p.end(), sum + p[i]);
      if (it != p.end()) {
        assert(p[it - p.begin()] - p[i] >= sum);
        dp[it - p.begin()].push_back({cnt + 1, p[it - p.begin()] - p[i]});
      }
    }
  }
  for (auto [cnt, _] : dp[n]) ans = max(ans, cnt);
  cout << ans << '\n';
}
void precompute() {}
signed main() {
#ifdef LOCAL
  // freopen("err.log", "w", stderr);
#endif
  precompute();
  int t = 1; // cin >> t;
  for (int tc = 1; tc <= t; tc++) {
    run_case(tc);
  }
}
/*
                                                0:                              
                                               0$P:                             
                                           ~~ wPPPI:                            
                                        "~:~ .w$$$PI:  .                        
                                      v~++:  w$$P$Pcc: ~~                       
                                    !vv+::~ w$$$P$$cc: ~!~                      
                                .  cIc::::~+X$$$PP$XIc~~!+"                     
          .   .                ~. vcIo+:!+~w$$$$PP$PIIv~:+~                     
      .                   . . "v vccI+:++!c$$$$$P$$$II:!+!:..  . .... ..  .   ..
 .. ....   . .. ......... ....!:!vcIo+++!~w$$$$$$P$$Ic:!!+:~ ......... . . .. . 
............................."::+coII+!!~"$$$w$$P$$PIIv!!::~! ..................
............................!!:v+coIII~~~+!:cvP$$$PoIv~!+!+~!...................
............................:!vv~coccv~vvcvcvcwPPPPII:~!:++"+...................
............................++:v"cI::cvvvvv+v:0$P$$I:~~!!:!!!...................
............................:c!v:c!ccv::+++!!+0P$$:!~~"!!!"++...................
..."....".............~"..+.:vo:vvc:X:!+!!!!!!0P$:++"~!"+~:v!.."....."..........
...."....."........."......++vIcovv:###w!!!!!!w0+!!!"~"~~+!+...".".........."...
."""......."...".$$"."""...!:ccIowv+!#!##!!!!!!!!!!!.~!~~v+"..."..""..........."
"""""."""""""".""$B"""..."".:wvoco++!o#0R#!!!!!!!!oPPP$":~~"".".""""."."""."".""
"""".""""""+cc+""..""..."$$."+:IccI"!~!!!$$!!!!+$R+$$"~!!!"~."..""""""."."""."""
""""""""+vcIo+"""""""""""$$$#.:co~co~!!!!!!!!!:vcI:~""+!~!~"""""".""""""""""""""
""""""":cwIo+.""""""""""~$$$$ "+co"~!!~!!!!!!!!!!!".~+v!!"""""""""""""""""""""""
"""""~Icow$$$~"""@~""""..#$$#~"":cII.~"~!!!!!!!!+".:.::~"""""""""""""~"""""""""~
""""~occooI$$B""#$#""~".P:""""~"~!Ico"""~!!!!+!~.. v+!"""B"""""""""""""""~""""""
"""~~cccwc+BR~""R$$$"""""""""~"~:c"+co.""~"+~!.  v:~""""".BB""~"~~"""~""""~"""""
"~"!vcccwc".~"""R$$$$$X""""~~"~PcI".+vc."""~. .~!~~""~""~w!!R.""""~"""""""!""~""
"""!!Icwo:""""+II$$$$$$$$!""""~0$o.""~:cI... !~"""~"":+:!!+!"!X""~"""~"""!v"""""
"""".."".~~"!IIIoo!#$$$$$$$"~"~wo$$"""""~~!~~"."~"""~$""~"$$~!~"""~~"~"~:c""~""~
"...""":+~"vIIIoIc~"P$$R@$$$~"."R#P~.~""""..  ".~~~v""@~~v~~~~~"c"~~~"~:c~~"~~~~
~..~~:!!~~c$$IIo:~~~$$$@@@$$v~~.+XX~.""""""".!" ~~"~~v~c"~~~~~cI+~~~~!II+!~"~~~~
"".".":II+$R$#!~~~~$$$#@@@$$0P!~!XXv!"~"""":!!. ~~~v!P~~~~~~~vo++~~~!Ioc+~~~~~~~
".~~.!~Ico$@B$$$$$$##B@@@@$#I00wXPPXv~~~"~o0!!~~.~~~~~~~~~~~!oo+:~~!Icc!+~"~~~~~
"~!!!~!I!":!$@@@@B@B@@@@@$0c0XPwXXXXXX~~+Xww+!!~~. "~~~~~~~~voI!!~~+occ!~~~~~~~+
+"!!..""~~::~@@@@@@@@@@@R$wIXPXXXPXXXPXPcw0w~!!!~... . .~~~~~..""""wwc++~"~~~:I~
~+!.""~~~"~P@@@@@@@@@@@@R$$0$#$$XXXXXXX0X00+!+!!"... .....vv"!~~~~~IoI!~"."!oc!~
"".~""~!+XXP#@@~:+o@@@@@@@@B$$$XXXXX00Xc00I++!!!......  . cI~!!!~~!:Ic~~"".oc~"~
"~.""~~~coXP:"~~":P@@@@@BB$$#$PXXXPXX0c000+++!!!.... ... vcI"!!!!!"!vv""~~::"~++
!!"."~~~~+."~"~"~.PRBBR#w$wXXXXXXXP00oXXX+++!!!.....   . II"+~!~!!.c+:""~.!!+ww:
~!+:+.."~."""""".X0PXXX+0oXXP0P0P00XoXo0++:+!~!.........Ic!!~!!~.!!v~".""~Iow++~
"+!~:."~.~.".~"~I0XXXX~:!P0XXwXoX0oXcXo+!!+!~!"..  ... :I~!!~!~~~"!~~".~~oI!!+~"
~!+!"~~~."..""..".!+v~~~"X0XXwXcXww0I0ov++~!!... ....c:~!!!!~!~"~~.!!!~~:o!!~""~
"!!"~~~""~..."~~~.~!!.~""o0Iw".$P$$0""~II!!!... ..cv~"!!~!!~!"~~""""~!!~w:~~""".
!."!!!"~~~~~~~~~~ "~"~"".v0""###$##$#wX"v:!!!+!!!!!~!!!+~+!~~"!.""..".v:I"""~~""
"~!!~+~~~~~~~~~"~".".".++c..""$##$#P$ww""+!!!!!!!!~!!!!"~!~.~"~."~."~!:~""."""..

*/
#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...