제출 #33958

#제출 시각아이디문제언어결과실행 시간메모리
33958mohammad_kilani수열 (APIO14_sequence)C++14
0 / 100
53 ms2800 KiB
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 2000000000 const int N = 100010; int n , k , arr[N] , sum[N]; long long ans; vector<int> va; void solve(vector<int> &v,int j,long long all){ if(j == k){ if(all > ans){ ans = all; va = v; } return ; } long long cur = 0 ; int k = 1; int idx = 0 ; int last = 0 ; for(int i=0;i<v.size();i++){ while(k <= v[i]){ long long f = sum[k] - sum[last]; long long s = sum[v[i]] - sum[k]; long long num = f * s; if(num > cur){ cur = num; idx = k; } k++; } last = v[i]; } v.push_back(idx); sort(v.begin(),v.end()); solve(v,j+1,all + cur); } int main() { //freopen("in.txt","r",stdin); scanf("%d%d",&n,&k); for(int i=1;i<=n;i++){ scanf("%d",&arr[i]); sum[i] = sum[i-1] + arr[i]; } vector<int> v; v.push_back(n); solve(v,0,0); cout << ans << endl;; for(int i=0;i<va.size()-1;i++){ printf("%d ",va[i]); } cout << endl; return 0; }

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

sequence.cpp: In function 'void solve(std::vector<int>&, int, long long int)':
sequence.cpp:22:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++){
               ^
sequence.cpp: In function 'int main()':
sequence.cpp:51:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<va.size()-1;i++){
               ^
sequence.cpp:42:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
                     ^
sequence.cpp:44:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&arr[i]);
                      ^
#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...