Submission #82926

# Submission time Handle Problem Language Result Execution time Memory
82926 2018-11-02T21:01:28 Z memetkagan44 Split the sequence (APIO14_sequence) C++11
0 / 100
11 ms 848 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
queue<pair<int,int> > q;
int n,k,a,top[100005];
unsigned long long ans;
int main(){
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        top[i]=top[i-1]+a;
    }
    q.push(make_pair(1,n));
    while(!q.empty() && k>0){
        k--;
        int l=q.front().first,r=q.front().second;
        q.pop();
        int i=l;
        if(l<r){
            for(;top[i]-top[l-1]<=(top[r]-top[l-1])/2;i++);
            if(abs((top[i-1]-top[l-1])-(top[r]-top[l-1])/2)<(top[i]-top[l-1])-(top[r]-top[l-1])/2)
                i--;
            ans+=(top[i]-top[l-1])*(top[r]-top[i]);
            v.push_back(i);
            q.push(make_pair(l,i));
            q.push(make_pair(i+1,r));
        }
    }
    printf("%lld\n",ans);
    for(int i=0;i<v.size();i++){
        printf("%d",v[i]);
        if(i<v.size()-1)
            printf(" ");
        else
            printf("\n");
    }
    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:30:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++){
                 ~^~~~~~~~~
sequence.cpp:32:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i<v.size()-1)
            ~^~~~~~~~~~~
sequence.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
sequence.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a);
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB contestant found the optimal answer: 108 == 108
2 Incorrect 2 ms 476 KB contestant didn't find the optimal answer: 951 < 999
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 476 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 476 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 2 ms 484 KB contestant found the optimal answer: 311760000 == 311760000
3 Incorrect 2 ms 492 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 556 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 592 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 848 KB declared answer doesn't correspond to the split scheme: declared = -1679059520, real = 19795776960
2 Halted 0 ms 0 KB -