제출 #915369

#제출 시각아이디문제언어결과실행 시간메모리
915369Pekiban수열 (APIO14_sequence)C++17
22 / 100
304 ms131072 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 1e5+2, mxK = 202; long long pref[mxN], dp[mxK][mxN], to[mxK][mxN], h[mxN], c, t, cnt; long double cord(int x, int y) { return (long double)(dp[c][y] - pref[y]*pref[y] + pref[x]*pref[x] - dp[c][x])/(pref[x] - pref[y]); // deljenje 0-om? } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> z; for (int i = 1; i <= n; ++i) { int x; cin >> x; if (!x) { z.push_back(i); continue; } ++t; h[t] = i; pref[t] = pref[t-1] + x; } n = t; if (n == 1) { cout << 0 << '\n'; for (int i = 1; i <= k; ++i) cout << i << ' '; return 0; } for (int i = 1; i <= k; ++i) { deque<int> dq = {1}; dp[i][1] = 0; for (int j = 2; j <= n; ++j) { while (dq.size() > 1 && cord(dq[0], dq[1]) <= pref[j]) dq.pop_front(); dp[i][j] = pref[j]*pref[dq[0]] + dp[i-1][dq[0]] - pref[dq[0]]*pref[dq[0]]; to[i][j] = dq[0]; while (dq.size() > 1 && cord(dq[dq.size()-1], dq[dq.size()-2]) >= cord(dq[dq.size()-2], j)) dq.pop_back(); dq.push_back(j); } ++c; } cout << dp[k][n] << '\n'; vector<int> v = {n}; for (int i = k; i >= 1 && to[i][v.back()]; --i) { v.push_back(to[i][v.back()]); cnt++; } while (v.size() < k+1) { v.push_back(z.back()); z.pop_back(); } reverse(v.begin(), v.end()); v.pop_back(); for (int i = 0; i < cnt; ++i) cout << h[v[i]] << ' '; for (int i = cnt; i < v.size(); ++i) cout << v[i] << ' '; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:51:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |     while (v.size() < k+1) {
      |            ~~~~~~~~~^~~~~
sequence.cpp:56:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for (int i = cnt; i < v.size(); ++i)    cout << v[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...