답안 #82920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82920 2018-11-02T20:42:53 Z memetkagan44 수열 (APIO14_sequence) C++11
0 / 100
12 ms 1656 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
queue<pair<int,int> > q;
int n,k,a,top[100005];
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;
        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:28:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++){
                 ~^~~~~~~~~
sequence.cpp:30: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);
         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB contestant found the optimal answer: 108 == 108
2 Incorrect 2 ms 552 KB contestant didn't find the optimal answer: 951 < 999
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 700 KB Integer 50 violates the range [1, 49]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 948 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 2 ms 964 KB contestant found the optimal answer: 311760000 == 311760000
3 Incorrect 2 ms 1076 KB position 3 occurs twice in split scheme
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1120 KB Integer 1000 violates the range [1, 999]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1124 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 1656 KB declared answer doesn't correspond to the split scheme: declared = -1679059520, real = 19795776960
2 Halted 0 ms 0 KB -