#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
ifstream f("teroristi2.in");
ofstream g("teroristi2.out");
int N;
int h[5005];
int dp[5005][5005];
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>N;
for(int i=1;i<=N;i++)
{
cin>>h[i];
}
for(int fin=1;fin<=N;fin++)
{
for(int start=fin;start>=1;start--)
{
vector<int> sp(N+5,0);
for(int j=fin;j>=start;j--)
{
sp[j]=sp[j+1]+h[j];
}
int sum=0,layers=0,cnt=fin;
for(int fin2=fin+1;fin2<=N;fin2++)
{
///dp[fin+1][fin2]=max(dp[fin+1][fin2],dp[start][fin]+layers)
sum+=h[fin2];
dp[fin+1][fin2]=max(dp[fin+1][fin2],dp[start][fin]+layers);
while(sum>sp[cnt]&&cnt>start+1)
{
cnt--;
}
if(sum==sp[cnt]&&cnt!=start)
{
layers++;
}
}
}
}
int rez=0;
for(int i=1;i<=N;i++)
{
rez=max(rez,dp[i][N]);
// cout<<i<<" "<<dp[i][N]<<'\n';
}
cout<<rez<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
2776 KB |
Output is correct |
2 |
Correct |
113 ms |
2956 KB |
Output is correct |
3 |
Correct |
112 ms |
2828 KB |
Output is correct |
4 |
Correct |
114 ms |
2732 KB |
Output is correct |
5 |
Correct |
114 ms |
2792 KB |
Output is correct |
6 |
Correct |
115 ms |
2732 KB |
Output is correct |
7 |
Correct |
118 ms |
2788 KB |
Output is correct |
8 |
Correct |
115 ms |
2756 KB |
Output is correct |
9 |
Correct |
115 ms |
2820 KB |
Output is correct |
10 |
Correct |
114 ms |
2828 KB |
Output is correct |
11 |
Correct |
113 ms |
2792 KB |
Output is correct |
12 |
Correct |
114 ms |
2844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
109 ms |
2776 KB |
Output is correct |
22 |
Correct |
113 ms |
2956 KB |
Output is correct |
23 |
Correct |
112 ms |
2828 KB |
Output is correct |
24 |
Correct |
114 ms |
2732 KB |
Output is correct |
25 |
Correct |
114 ms |
2792 KB |
Output is correct |
26 |
Correct |
115 ms |
2732 KB |
Output is correct |
27 |
Correct |
118 ms |
2788 KB |
Output is correct |
28 |
Correct |
115 ms |
2756 KB |
Output is correct |
29 |
Correct |
115 ms |
2820 KB |
Output is correct |
30 |
Correct |
114 ms |
2828 KB |
Output is correct |
31 |
Correct |
113 ms |
2792 KB |
Output is correct |
32 |
Correct |
114 ms |
2844 KB |
Output is correct |
33 |
Correct |
108 ms |
2712 KB |
Output is correct |
34 |
Correct |
111 ms |
2720 KB |
Output is correct |
35 |
Correct |
112 ms |
2784 KB |
Output is correct |
36 |
Correct |
113 ms |
2868 KB |
Output is correct |
37 |
Correct |
114 ms |
2772 KB |
Output is correct |
38 |
Correct |
116 ms |
2824 KB |
Output is correct |
39 |
Correct |
119 ms |
2764 KB |
Output is correct |
40 |
Correct |
117 ms |
2724 KB |
Output is correct |
41 |
Correct |
115 ms |
2820 KB |
Output is correct |
42 |
Correct |
115 ms |
2788 KB |
Output is correct |
43 |
Correct |
116 ms |
2796 KB |
Output is correct |
44 |
Correct |
113 ms |
2728 KB |
Output is correct |
45 |
Correct |
115 ms |
2828 KB |
Output is correct |
46 |
Correct |
115 ms |
2724 KB |
Output is correct |
47 |
Correct |
115 ms |
2728 KB |
Output is correct |
48 |
Correct |
118 ms |
2752 KB |
Output is correct |
49 |
Correct |
118 ms |
2820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
109 ms |
2776 KB |
Output is correct |
22 |
Correct |
113 ms |
2956 KB |
Output is correct |
23 |
Correct |
112 ms |
2828 KB |
Output is correct |
24 |
Correct |
114 ms |
2732 KB |
Output is correct |
25 |
Correct |
114 ms |
2792 KB |
Output is correct |
26 |
Correct |
115 ms |
2732 KB |
Output is correct |
27 |
Correct |
118 ms |
2788 KB |
Output is correct |
28 |
Correct |
115 ms |
2756 KB |
Output is correct |
29 |
Correct |
115 ms |
2820 KB |
Output is correct |
30 |
Correct |
114 ms |
2828 KB |
Output is correct |
31 |
Correct |
113 ms |
2792 KB |
Output is correct |
32 |
Correct |
114 ms |
2844 KB |
Output is correct |
33 |
Correct |
108 ms |
2712 KB |
Output is correct |
34 |
Correct |
111 ms |
2720 KB |
Output is correct |
35 |
Correct |
112 ms |
2784 KB |
Output is correct |
36 |
Correct |
113 ms |
2868 KB |
Output is correct |
37 |
Correct |
114 ms |
2772 KB |
Output is correct |
38 |
Correct |
116 ms |
2824 KB |
Output is correct |
39 |
Correct |
119 ms |
2764 KB |
Output is correct |
40 |
Correct |
117 ms |
2724 KB |
Output is correct |
41 |
Correct |
115 ms |
2820 KB |
Output is correct |
42 |
Correct |
115 ms |
2788 KB |
Output is correct |
43 |
Correct |
116 ms |
2796 KB |
Output is correct |
44 |
Correct |
113 ms |
2728 KB |
Output is correct |
45 |
Correct |
115 ms |
2828 KB |
Output is correct |
46 |
Correct |
115 ms |
2724 KB |
Output is correct |
47 |
Correct |
115 ms |
2728 KB |
Output is correct |
48 |
Correct |
118 ms |
2752 KB |
Output is correct |
49 |
Correct |
118 ms |
2820 KB |
Output is correct |
50 |
Execution timed out |
1080 ms |
11268 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |