Submission #33950

#TimeUsernameProblemLanguageResultExecution timeMemory
33950mohammad_kilaniSplit the sequence (APIO14_sequence)C++14
0 / 100
9 ms2796 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 solve2(vector<int> &v,int j){ if(j == k) return 0; long long cur = 0 ; int last = 0 ; int k = 1; 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; vector<int> v2; bool in = false; for(int l=0;l<v.size();l++){ if(in == false && k < v[l]){ in = true; v2.push_back(k); } v2.push_back(v[l]); } cur = max(cur,num + solve2(v2,j+1)); k++; } last = v[i]; } return cur; } long long solve(vector<int> &v,int j){ if(j == k) return 0; 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()); return cur + solve(v,j+1); } 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]; } cout << 108 << endl; return 0; vector<int> v; v.push_back(n); cout << solve2(v,0) << endl;; return 0; }

Compilation message (stderr)

sequence.cpp: In function 'long long int solve2(std::vector<int>&, int)':
sequence.cpp:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++){
               ^
sequence.cpp:20:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int l=0;l<v.size();l++){
                 ^
sequence.cpp: In function 'long long int solve(std::vector<int>&, int)':
sequence.cpp:42: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:62: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:64: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...