제출 #82927

#제출 시각아이디문제언어결과실행 시간메모리
82927memetkagan44수열 (APIO14_sequence)C++11
0 / 100
11 ms816 KiB
#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; 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; }

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...