제출 #716854

#제출 시각아이디문제언어결과실행 시간메모리
716854vjudge1수열 (APIO14_sequence)C++17
71 / 100
59 ms131072 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int maxn = 1e5 + 100; const int mod = (int)1e9+7; int n, k; int a[maxn]; ll pref[maxn]; ll dp[maxn][202]; int p[maxn][202]; ll d[maxn]; ld inter(int i, int j) { return (ld)(d[i] - d[j])/(pref[j] - pref[i]); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = pref[i-1] + a[i]; } for(int i = 1; i <= n; i++) { dp[i][0] = 0; } for(int it = 1; it <= k; it++) { int j = 0; for(int i = 0; i <= n; i++) { d[i] = dp[i][it-1] - pref[i]*pref[i]; } vector<int> st; st.push_back(0); for(int i = 1; i <= n; i++) { if(j >= st.size()) { j = (int)st.size() - 1; } while(j > 0 && d[st[j]] + pref[i] * pref[st[j]] < d[st[j-1]] + pref[i] * pref[st[j-1]]) j--; while(j + 1 < st.size() && d[st[j]] + pref[i] * pref[st[j]] <= d[st[j+1]] + pref[i] * pref[st[j+1]]) j++; int t = st[j]; p[i][it] = t; dp[i][it] = pref[t] * pref[i] + d[t]; int sz = (int)st.size(); while(sz > 0 && pref[i] == pref[st[sz-1]]) { st.pop_back(); sz--; } while(sz > 1 && inter(st[sz - 1], st[sz-2]) > inter(st[sz-2], i)) { st.pop_back(); sz--; } st.push_back(i); } } vector<int> cur; int last = n; for(int i = k; i >= 1; i--) { last = p[last][i]; cur.push_back(last); } cout << dp[n][k] << "\n"; reverse(cur.begin(), cur.end()); for(int x: cur) cout << x << " "; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             if(j >= st.size()) {
      |                ~~^~~~~~~~~~~~
sequence.cpp:41:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             while(j + 1 < st.size() && d[st[j]] + pref[i] * pref[st[j]] <= d[st[j+1]] + pref[i] * pref[st[j+1]]) j++;
      |                   ~~~~~~^~~~~~~~~~~
#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...