Submission #42703

# Submission time Handle Problem Language Result Execution time Memory
42703 2018-03-02T21:44:48 Z repeating Split the sequence (APIO14_sequence) C++11
11 / 100
2000 ms 17156 KB
#include <bits/stdc++.h>

#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%Id",&x)
#define SF2(x,y) scanf("%Id%Id",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()

using namespace std;
const long long INF = 1e9+1;
const long long MOD = 1e9+7;
const int MX=100015;
int a[MX];
int n,m;
int SUM;
vector<int> v;
int val;
ll dp[10005][202];
int su[10005];
ll DP(int x,int k){
    if(k==0)R 0;
    if(x==n)R -INF;
    ll sum=0;
    ll &ret=dp[x][k];
    if(ret!=-1)R ret;
    ret=-INF;
    ll z;
    for(int i=x;i<n;i++){
        z=DP(i+1,k-1);
//        cout<<z<<endl;
        if(z==-INF)break;
        sum+=a[i];
        if(val>sum)continue;
        ret=max(ret,z+(sum*su[i+1]));
//        cout<<sum*su[i+1]<<endl;
    }
    R ret;
}
void fs(int x,int k){
    if(k==0)R;
    ll sum=0;
    ll ret=dp[x][k];
    ll z;
    for(int i=x;i<n;i++){
        z=DP(i+1,k-1);
        if(z==-INF)break;
        sum+=a[i];
        if(val>sum)continue;
        if(ret==z+(sum*su[i+1])){
            cout<<i+1<<" ";
            fs(i+1,k-1);
            R;
        }
    }
}
ll solve(){
    int l=0,r=1e9+1;
    W(l<r){
//        l=5,r=5;
        int mid=(l+r)/2;
        int k=m+1;
        for(int i=0;i<n;i++){
            int sum=0;
            W(i<n){
                sum+=a[i];
                if(sum>=mid){
                    k--;
                    break;
                }
                i++;
            }
            if(k==0){
                val=mid;
                l=mid+1;
                break;
            }
        }
        if(k){
            r=mid;
        }
    }
    ll res=DP(0,m);
    R res;
}

int main(){
    MEM(dp,-1);
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        SUM+=a[i];
    }
    for(int i=n-1;i>=0;i--)
        su[i]=su[i+1]+a[i];
    int z=SUM;
    ll res=solve();
    cout<<res<<endl;
    fs(0,m);
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:108:9: warning: unused variable 'z' [-Wunused-variable]
     int z=SUM;
         ^
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16120 KB contestant found the optimal answer: 108 == 108
2 Correct 15 ms 16120 KB contestant found the optimal answer: 999 == 999
3 Correct 12 ms 16152 KB contestant found the optimal answer: 0 == 0
4 Correct 13 ms 16456 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 13 ms 16456 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 12 ms 16456 KB contestant found the optimal answer: 1 == 1
7 Correct 13 ms 16456 KB contestant found the optimal answer: 1 == 1
8 Correct 12 ms 16456 KB contestant found the optimal answer: 1 == 1
9 Correct 12 ms 16456 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 14 ms 16456 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 15 ms 16456 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 15 ms 16456 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 12 ms 16460 KB contestant found the optimal answer: 140072 == 140072
14 Correct 13 ms 16468 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 13 ms 16516 KB contestant found the optimal answer: 805 == 805
16 Correct 13 ms 16652 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 12 ms 16652 KB contestant found the optimal answer: 999919994 == 999919994
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16652 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 13 ms 16652 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 13 ms 16652 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 13 ms 16652 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 12 ms 16652 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 12 ms 16652 KB contestant found the optimal answer: 933702 == 933702
7 Incorrect 12 ms 16652 KB contestant didn't find the optimal answer: 25079535562 < 25082842857
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16652 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 13 ms 16652 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 13 ms 16652 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 13 ms 16652 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 15 ms 16652 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 13 ms 16652 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 12 ms 16652 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Incorrect 15 ms 16652 KB contestant didn't find the optimal answer: 193549614 < 193556962
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16652 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 14 ms 16652 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 148 ms 16672 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 16 ms 16672 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 167 ms 16720 KB contestant found the optimal answer: 679388326 == 679388326
6 Incorrect 135 ms 16720 KB contestant didn't find the optimal answer: 4699030286 < 4699030287
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 717 ms 16880 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Incorrect 155 ms 16880 KB contestant didn't find the optimal answer: 1301400195 < 1326260195
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2051 ms 17156 KB Time limit exceeded
2 Halted 0 ms 0 KB -