// cre: Nguyen Ngoc Hung - Train VOI 2024 :>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <unordered_set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <array>
#include <cassert>
#include <random>
using namespace std;
#define __nnhzzz__ signed main()
#define BIT(i,j) ((i>>j)&1LL)
#define MASK(i) (1LL<<i)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define REPDIS(i,be,en,j) for(int i = (be); i<=(en); i+=j)
#define REPD(i,be,en) for(int i = (be); i>=(en); i--)
#define REP(i,be,en) for(int i = (be); i<=(en); i++)
#define int ll
//-------------------------------------------------------------//
const int oo = 1e9,LOG = 20,MAXN = 5e5+7,N = 1e2+3;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
/*
----------------------------------------------------------------
END OF TEMPLATE
----------------------------------------------------------------
Nguyen Ngoc Hung - nnhzzz
Training for VOI24 gold medal
----------------------------------------------------------------
*/
int a[MAXN],pre[MAXN],dp[MAXN],lst[MAXN],par[MAXN];
int n;
void sub3(){
REP(i,1,n){
dp[i] = 1;
lst[i] = pre[i];
REP(j,1,i){
int now = pre[i]-pre[j-1];
if(lst[j-1]<=now && maxi(dp[i],dp[j-1]+1)){
lst[i] = now;
}else{
if(lst[j-1]<=now && dp[i]==dp[j-1]+1) mini(lst[i],now);
}
}
// cerr << dp[i] << " ";
}
cout << *max_element(dp,dp+n+1);
}
void sub5(){
REP(i,1,n){
dp[i] = 1; // lst[i] = pre[i];
int &x = par[i]; maxi(x,par[i-1]);
// cerr << x << " ";
dp[i] = dp[x]+1;
int pos = lower_bound(pre,pre+n+1,pre[i]*2-pre[x])-pre;
maxi(par[pos],i);
}
cout << dp[n];
}
void solve(){
cin >> n;
REP(i,1,n){
cin >> a[i];
pre[i] = pre[i-1]+a[i];
}
// sub5(); return ;
if(n<=3000){
sub3(); return ;
}
sub5();
}
__nnhzzz__{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "test"
if(fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
#define name1 "nnhzzz"
if(fopen(name1".inp","r")){
freopen(name1".inp","r",stdin);
freopen(name1".out","w",stdout);
}
int test = 1;
while(test--){
solve();
}
cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
return 0;
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
129 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
segments.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
130 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:134:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
134 | freopen(name1".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:135:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
135 | freopen(name1".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6624 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6488 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
6488 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6624 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6488 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
6488 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
4 ms |
6488 KB |
Output is correct |
32 |
Correct |
7 ms |
6492 KB |
Output is correct |
33 |
Correct |
12 ms |
6492 KB |
Output is correct |
34 |
Correct |
5 ms |
6492 KB |
Output is correct |
35 |
Correct |
5 ms |
6608 KB |
Output is correct |
36 |
Correct |
9 ms |
6492 KB |
Output is correct |
37 |
Correct |
7 ms |
6492 KB |
Output is correct |
38 |
Correct |
5 ms |
6488 KB |
Output is correct |
39 |
Correct |
10 ms |
6648 KB |
Output is correct |
40 |
Correct |
14 ms |
6748 KB |
Output is correct |
41 |
Correct |
5 ms |
6488 KB |
Output is correct |
42 |
Correct |
5 ms |
6492 KB |
Output is correct |
43 |
Correct |
7 ms |
6492 KB |
Output is correct |
44 |
Correct |
5 ms |
6492 KB |
Output is correct |
45 |
Correct |
5 ms |
6644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6624 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6488 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
6488 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
4 ms |
6488 KB |
Output is correct |
32 |
Correct |
7 ms |
6492 KB |
Output is correct |
33 |
Correct |
12 ms |
6492 KB |
Output is correct |
34 |
Correct |
5 ms |
6492 KB |
Output is correct |
35 |
Correct |
5 ms |
6608 KB |
Output is correct |
36 |
Correct |
9 ms |
6492 KB |
Output is correct |
37 |
Correct |
7 ms |
6492 KB |
Output is correct |
38 |
Correct |
5 ms |
6488 KB |
Output is correct |
39 |
Correct |
10 ms |
6648 KB |
Output is correct |
40 |
Correct |
14 ms |
6748 KB |
Output is correct |
41 |
Correct |
5 ms |
6488 KB |
Output is correct |
42 |
Correct |
5 ms |
6492 KB |
Output is correct |
43 |
Correct |
7 ms |
6492 KB |
Output is correct |
44 |
Correct |
5 ms |
6492 KB |
Output is correct |
45 |
Correct |
5 ms |
6644 KB |
Output is correct |
46 |
Correct |
7 ms |
9304 KB |
Output is correct |
47 |
Correct |
10 ms |
10596 KB |
Output is correct |
48 |
Correct |
12 ms |
10844 KB |
Output is correct |
49 |
Correct |
14 ms |
11096 KB |
Output is correct |
50 |
Correct |
14 ms |
11100 KB |
Output is correct |
51 |
Correct |
14 ms |
11184 KB |
Output is correct |
52 |
Correct |
9 ms |
5848 KB |
Output is correct |
53 |
Correct |
5 ms |
5212 KB |
Output is correct |
54 |
Correct |
10 ms |
10332 KB |
Output is correct |
55 |
Correct |
14 ms |
11424 KB |
Output is correct |
56 |
Correct |
12 ms |
10436 KB |
Output is correct |
57 |
Correct |
10 ms |
10604 KB |
Output is correct |
58 |
Correct |
10 ms |
10588 KB |
Output is correct |
59 |
Correct |
12 ms |
10756 KB |
Output is correct |
60 |
Correct |
12 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6624 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6488 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
6488 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
4 ms |
6488 KB |
Output is correct |
32 |
Correct |
7 ms |
6492 KB |
Output is correct |
33 |
Correct |
12 ms |
6492 KB |
Output is correct |
34 |
Correct |
5 ms |
6492 KB |
Output is correct |
35 |
Correct |
5 ms |
6608 KB |
Output is correct |
36 |
Correct |
9 ms |
6492 KB |
Output is correct |
37 |
Correct |
7 ms |
6492 KB |
Output is correct |
38 |
Correct |
5 ms |
6488 KB |
Output is correct |
39 |
Correct |
10 ms |
6648 KB |
Output is correct |
40 |
Correct |
14 ms |
6748 KB |
Output is correct |
41 |
Correct |
5 ms |
6488 KB |
Output is correct |
42 |
Correct |
5 ms |
6492 KB |
Output is correct |
43 |
Correct |
7 ms |
6492 KB |
Output is correct |
44 |
Correct |
5 ms |
6492 KB |
Output is correct |
45 |
Correct |
5 ms |
6644 KB |
Output is correct |
46 |
Correct |
7 ms |
9304 KB |
Output is correct |
47 |
Correct |
10 ms |
10596 KB |
Output is correct |
48 |
Correct |
12 ms |
10844 KB |
Output is correct |
49 |
Correct |
14 ms |
11096 KB |
Output is correct |
50 |
Correct |
14 ms |
11100 KB |
Output is correct |
51 |
Correct |
14 ms |
11184 KB |
Output is correct |
52 |
Correct |
9 ms |
5848 KB |
Output is correct |
53 |
Correct |
5 ms |
5212 KB |
Output is correct |
54 |
Correct |
10 ms |
10332 KB |
Output is correct |
55 |
Correct |
14 ms |
11424 KB |
Output is correct |
56 |
Correct |
12 ms |
10436 KB |
Output is correct |
57 |
Correct |
10 ms |
10604 KB |
Output is correct |
58 |
Correct |
10 ms |
10588 KB |
Output is correct |
59 |
Correct |
12 ms |
10756 KB |
Output is correct |
60 |
Correct |
12 ms |
10588 KB |
Output is correct |
61 |
Correct |
39 ms |
15416 KB |
Output is correct |
62 |
Correct |
36 ms |
17488 KB |
Output is correct |
63 |
Correct |
47 ms |
19540 KB |
Output is correct |
64 |
Correct |
65 ms |
22068 KB |
Output is correct |
65 |
Correct |
66 ms |
22356 KB |
Output is correct |
66 |
Correct |
65 ms |
22280 KB |
Output is correct |
67 |
Correct |
53 ms |
18992 KB |
Output is correct |
68 |
Correct |
27 ms |
14928 KB |
Output is correct |
69 |
Correct |
48 ms |
18616 KB |
Output is correct |
70 |
Correct |
65 ms |
22352 KB |
Output is correct |
71 |
Correct |
51 ms |
19540 KB |
Output is correct |
72 |
Correct |
59 ms |
19740 KB |
Output is correct |
73 |
Correct |
52 ms |
20304 KB |
Output is correct |
74 |
Correct |
57 ms |
20804 KB |
Output is correct |
75 |
Correct |
57 ms |
20820 KB |
Output is correct |