제출 #985472

#제출 시각아이디문제언어결과실행 시간메모리
985472Math4Life2020수열 (APIO14_sequence)C++17
0 / 100
13 ms2256 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; void solve(long long N, long long K, vector<long long> a) { long long tval = 0; for (long long i=0;i<N;i++) { tval += a[i]; } tval = tval*tval; deque<long long> d[K+1]; long long dsums[K+1]; for (long long i=0;i<=K;i++) { dsums[i]=0; } for (long long i=0;i<N;i++) { d[0].push_back(a[i]); dsums[0] += a[i]; } for (long long t=0;t<(2*N);t++) { for (long long i=0;i<K;i++) { while (1) { long long r = d[i].back(); if (max(dsums[i]-r,dsums[i+1]+r)<max(dsums[i],dsums[i+1])) { d[i].pop_back(); d[i+1].push_front(r); dsums[i]=dsums[i]-r; dsums[i+1]=dsums[i+1]+r; } else { break; } } } } for (long long i=0;i<=K;i++) { tval -= dsums[i]*dsums[i]; /*cout << "i="<<i<<", dsums="<<dsums[i]<<"\n"; for (long long x: d[i]) { cout << "term: "<<x<<"\n"; }*/ } tval = tval/2; cout << tval; } int main() { long long N,K; cin >> N >> K; vector<long long> a; for (long long i=0;i<N;i++) { long long x; cin >> x; if (x != 0) { a.push_back(x); } } K = min(K,(long long) (a.size()-1)); solve(a.size(),K,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...