#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
llo it[500001];
llo n;
llo pre[500001];
llo dp[500001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<n;i++){
cin>>it[i];
pre[i+1]=pre[i]+it[i];
}
llo ans=1;
vector<pair<llo,pair<llo,llo>>> ss;
for(llo i=1;i<=n;i++){
for(llo j=0;j<i;j++){
ss.pb({pre[i]-pre[j],{j,i}});
}
}
sort(ss.begin(),ss.end());
for(llo i=1;i<=n;i++){
dp[i]=-1;
}
for(auto j:ss){
if(dp[j.b.a]==-1){
continue;
}
dp[j.b.b]=max(dp[j.b.a]+1,dp[j.b.b]);
}
cout<<dp[n]<<endl;
return 0;
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:21:6: warning: unused variable 'ans' [-Wunused-variable]
llo ans=1;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
3604 KB |
Output is correct |
17 |
Correct |
14 ms |
3572 KB |
Output is correct |
18 |
Correct |
15 ms |
3572 KB |
Output is correct |
19 |
Correct |
16 ms |
3572 KB |
Output is correct |
20 |
Correct |
17 ms |
3572 KB |
Output is correct |
21 |
Correct |
15 ms |
3572 KB |
Output is correct |
22 |
Correct |
10 ms |
3572 KB |
Output is correct |
23 |
Correct |
6 ms |
2040 KB |
Output is correct |
24 |
Correct |
17 ms |
3572 KB |
Output is correct |
25 |
Correct |
15 ms |
3572 KB |
Output is correct |
26 |
Correct |
16 ms |
3572 KB |
Output is correct |
27 |
Correct |
20 ms |
3572 KB |
Output is correct |
28 |
Correct |
17 ms |
3572 KB |
Output is correct |
29 |
Correct |
18 ms |
3572 KB |
Output is correct |
30 |
Correct |
16 ms |
3572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
3604 KB |
Output is correct |
17 |
Correct |
14 ms |
3572 KB |
Output is correct |
18 |
Correct |
15 ms |
3572 KB |
Output is correct |
19 |
Correct |
16 ms |
3572 KB |
Output is correct |
20 |
Correct |
17 ms |
3572 KB |
Output is correct |
21 |
Correct |
15 ms |
3572 KB |
Output is correct |
22 |
Correct |
10 ms |
3572 KB |
Output is correct |
23 |
Correct |
6 ms |
2040 KB |
Output is correct |
24 |
Correct |
17 ms |
3572 KB |
Output is correct |
25 |
Correct |
15 ms |
3572 KB |
Output is correct |
26 |
Correct |
16 ms |
3572 KB |
Output is correct |
27 |
Correct |
20 ms |
3572 KB |
Output is correct |
28 |
Correct |
17 ms |
3572 KB |
Output is correct |
29 |
Correct |
18 ms |
3572 KB |
Output is correct |
30 |
Correct |
16 ms |
3572 KB |
Output is correct |
31 |
Correct |
744 ms |
197780 KB |
Output is correct |
32 |
Correct |
651 ms |
197524 KB |
Output is correct |
33 |
Correct |
703 ms |
197520 KB |
Output is correct |
34 |
Correct |
709 ms |
197520 KB |
Output is correct |
35 |
Correct |
785 ms |
197524 KB |
Output is correct |
36 |
Correct |
695 ms |
197528 KB |
Output is correct |
37 |
Correct |
453 ms |
99068 KB |
Output is correct |
38 |
Correct |
280 ms |
49816 KB |
Output is correct |
39 |
Correct |
792 ms |
197524 KB |
Output is correct |
40 |
Correct |
676 ms |
197576 KB |
Output is correct |
41 |
Correct |
790 ms |
197520 KB |
Output is correct |
42 |
Correct |
726 ms |
197524 KB |
Output is correct |
43 |
Correct |
727 ms |
197524 KB |
Output is correct |
44 |
Correct |
758 ms |
197524 KB |
Output is correct |
45 |
Correct |
739 ms |
197656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
3604 KB |
Output is correct |
17 |
Correct |
14 ms |
3572 KB |
Output is correct |
18 |
Correct |
15 ms |
3572 KB |
Output is correct |
19 |
Correct |
16 ms |
3572 KB |
Output is correct |
20 |
Correct |
17 ms |
3572 KB |
Output is correct |
21 |
Correct |
15 ms |
3572 KB |
Output is correct |
22 |
Correct |
10 ms |
3572 KB |
Output is correct |
23 |
Correct |
6 ms |
2040 KB |
Output is correct |
24 |
Correct |
17 ms |
3572 KB |
Output is correct |
25 |
Correct |
15 ms |
3572 KB |
Output is correct |
26 |
Correct |
16 ms |
3572 KB |
Output is correct |
27 |
Correct |
20 ms |
3572 KB |
Output is correct |
28 |
Correct |
17 ms |
3572 KB |
Output is correct |
29 |
Correct |
18 ms |
3572 KB |
Output is correct |
30 |
Correct |
16 ms |
3572 KB |
Output is correct |
31 |
Correct |
744 ms |
197780 KB |
Output is correct |
32 |
Correct |
651 ms |
197524 KB |
Output is correct |
33 |
Correct |
703 ms |
197520 KB |
Output is correct |
34 |
Correct |
709 ms |
197520 KB |
Output is correct |
35 |
Correct |
785 ms |
197524 KB |
Output is correct |
36 |
Correct |
695 ms |
197528 KB |
Output is correct |
37 |
Correct |
453 ms |
99068 KB |
Output is correct |
38 |
Correct |
280 ms |
49816 KB |
Output is correct |
39 |
Correct |
792 ms |
197524 KB |
Output is correct |
40 |
Correct |
676 ms |
197576 KB |
Output is correct |
41 |
Correct |
790 ms |
197520 KB |
Output is correct |
42 |
Correct |
726 ms |
197524 KB |
Output is correct |
43 |
Correct |
727 ms |
197524 KB |
Output is correct |
44 |
Correct |
758 ms |
197524 KB |
Output is correct |
45 |
Correct |
739 ms |
197656 KB |
Output is correct |
46 |
Runtime error |
355 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
3604 KB |
Output is correct |
17 |
Correct |
14 ms |
3572 KB |
Output is correct |
18 |
Correct |
15 ms |
3572 KB |
Output is correct |
19 |
Correct |
16 ms |
3572 KB |
Output is correct |
20 |
Correct |
17 ms |
3572 KB |
Output is correct |
21 |
Correct |
15 ms |
3572 KB |
Output is correct |
22 |
Correct |
10 ms |
3572 KB |
Output is correct |
23 |
Correct |
6 ms |
2040 KB |
Output is correct |
24 |
Correct |
17 ms |
3572 KB |
Output is correct |
25 |
Correct |
15 ms |
3572 KB |
Output is correct |
26 |
Correct |
16 ms |
3572 KB |
Output is correct |
27 |
Correct |
20 ms |
3572 KB |
Output is correct |
28 |
Correct |
17 ms |
3572 KB |
Output is correct |
29 |
Correct |
18 ms |
3572 KB |
Output is correct |
30 |
Correct |
16 ms |
3572 KB |
Output is correct |
31 |
Correct |
744 ms |
197780 KB |
Output is correct |
32 |
Correct |
651 ms |
197524 KB |
Output is correct |
33 |
Correct |
703 ms |
197520 KB |
Output is correct |
34 |
Correct |
709 ms |
197520 KB |
Output is correct |
35 |
Correct |
785 ms |
197524 KB |
Output is correct |
36 |
Correct |
695 ms |
197528 KB |
Output is correct |
37 |
Correct |
453 ms |
99068 KB |
Output is correct |
38 |
Correct |
280 ms |
49816 KB |
Output is correct |
39 |
Correct |
792 ms |
197524 KB |
Output is correct |
40 |
Correct |
676 ms |
197576 KB |
Output is correct |
41 |
Correct |
790 ms |
197520 KB |
Output is correct |
42 |
Correct |
726 ms |
197524 KB |
Output is correct |
43 |
Correct |
727 ms |
197524 KB |
Output is correct |
44 |
Correct |
758 ms |
197524 KB |
Output is correct |
45 |
Correct |
739 ms |
197656 KB |
Output is correct |
46 |
Runtime error |
355 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
47 |
Halted |
0 ms |
0 KB |
- |