# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
681642 | Karuk | Bigger segments (IZhO19_segments) | C++14 | 0 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
long long sum[3001][3001];
long long minsc[3001][3004];
const long long MAX=1e17;
void bin(int begnum,int ennum,int begfrom,int endfrom,int cur) {
if(begnum>ennum)return;
int mid=(begnum+ennum)/2;
int ind;
int indmax=endfrom;
bool flag=0;
for(ind=begfrom;ind<=endfrom;ind++) {
if(sum[ind+1][cur]>=minsc[ind][mid-1] && sum[ind+1][cur]<minsc[cur][mid]) {
minsc[cur][mid]=sum[ind+1][cur];
indmax=ind;
flag=1;
}
}
if(begnum==ennum)return;
bin(begnum,mid,begfrom,endfrom,cur);
bin(mid+1,ennum,begfrom,endfrom,cur);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;cin>>n;
long long a[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++) {
long long su=0;
for(int j=i;j<n;j++) {
su+=a[j];
sum[i][j]=su;
}
}
for(int i=0;i<n;i++) {
for(int j=0;j<=n;j++) {
minsc[i][j]=MAX;
}
}
int ans=1;
for(int i=0;i<n;i++) {
minsc[i][1]=sum[0][i];
if(i==0)continue;
//bin(2,i+1,0,i-1,i);
for(int j=0;j<i;j++) {
for(int t=2;t<=i+1;t++) {
if(sum[j][i]>=minsc[j][t-1] && sum[j][i]<minsc[i][t]) {
minsc[i][t]=sum[j][i];
}
}
}
for(int j=1;j<=i;j++) {
if(minsc[i][j]!=MAX)ans=max(ans,j);
}
}
cout<<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |