#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=3e3+50;
const int mod=1e9+7;
int n,i,nr,j,t,l,r,mid;
ll a[nmax],f[nmax][nmax],pr[nmax];
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i];
pr[i]=pr[i-1]+a[i];
}
for(i=0;i<=n;i++)for(j=0;j<=n;j++)f[i][j]=llinf;
f[0][0]=0;
for(i=1;i<=n;i++)
{
for(j=i;j<=n;j++)
{
for(l=0;l<j;l++)if(f[i-1][l]<llinf)break;
r=j-1;
while(l<=r)
{
mid=(l+r)/2;
if(f[i-1][mid]<=pr[j]-pr[mid])
{
f[i][j]=pr[j]-pr[mid];
l=mid+1;
}
else r=mid-1;
}
/*for(t=j-1;t>=0;t--)
{
if(f[i-1][t]<=pr[j]-pr[t])
{
f[i][j]=pr[j]-pr[t];
break;
}
}*/
}
if(f[i][n]<llinf)nr=max(nr,i);
}
cout<<nr<<endl;
return 0;
}
Compilation message
segments.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
segments.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
2 |
Correct |
16 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
2 |
Correct |
16 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
424 KB |
Output is correct |
16 |
Correct |
40 ms |
4396 KB |
Output is correct |
17 |
Correct |
40 ms |
4392 KB |
Output is correct |
18 |
Correct |
38 ms |
4392 KB |
Output is correct |
19 |
Correct |
28 ms |
4344 KB |
Output is correct |
20 |
Correct |
26 ms |
4316 KB |
Output is correct |
21 |
Incorrect |
39 ms |
4396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
2 |
Correct |
16 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
424 KB |
Output is correct |
16 |
Correct |
40 ms |
4396 KB |
Output is correct |
17 |
Correct |
40 ms |
4392 KB |
Output is correct |
18 |
Correct |
38 ms |
4392 KB |
Output is correct |
19 |
Correct |
28 ms |
4344 KB |
Output is correct |
20 |
Correct |
26 ms |
4316 KB |
Output is correct |
21 |
Incorrect |
39 ms |
4396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
2 |
Correct |
16 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
424 KB |
Output is correct |
16 |
Correct |
40 ms |
4396 KB |
Output is correct |
17 |
Correct |
40 ms |
4392 KB |
Output is correct |
18 |
Correct |
38 ms |
4392 KB |
Output is correct |
19 |
Correct |
28 ms |
4344 KB |
Output is correct |
20 |
Correct |
26 ms |
4316 KB |
Output is correct |
21 |
Incorrect |
39 ms |
4396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
2 |
Correct |
16 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
424 KB |
Output is correct |
16 |
Correct |
40 ms |
4396 KB |
Output is correct |
17 |
Correct |
40 ms |
4392 KB |
Output is correct |
18 |
Correct |
38 ms |
4392 KB |
Output is correct |
19 |
Correct |
28 ms |
4344 KB |
Output is correct |
20 |
Correct |
26 ms |
4316 KB |
Output is correct |
21 |
Incorrect |
39 ms |
4396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |