Submission #752518

#TimeUsernameProblemLanguageResultExecution timeMemory
752518inventiontimeSplit the sequence (APIO14_sequence)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define int ll #define endl '\n' //comment for interactive #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define re resize #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define all1(x) (x).begin()+1, (x).end() #define loop(i, n) for(int i = 0; i < n; i++) #define loop1(i, n) for(int i = 1; i <= n; i++) #define print(x) cout << #x << ": " << x << endl << flush typedef long long ll; typedef vector<int> vi; typedef array<int, 2> ii; typedef array<int, 3> ti; typedef vector<ii> vii; typedef vector<ti> vti; typedef vector<vi> vvi; typedef priority_queue<int> pq; template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; } template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; } const int inf = 1e17; struct line { int m, c, id; int eval(int x) { return m*x + c; } }; double isect(line a, line b) { assert(b.m != a.m); return (double) (a.c - b.c) / (b.m - a.m); } deque<line> dq[k+1]; ii dp[n+1][k+1]; void solve() { int n, k; cin >> n >> k; k++; vi a(n+1); loop1(i, n) cin >> a[i]; vi pref(n+1); loop1(i, n) pref[i] = pref[i-1] + a[i]; dq[0].pb({0, 0, 0}); loop(i, k+1) dp[0][i] = {0, 0}; loop1(i, n) for(int j = k; j >= 1; j--) if(!dq[j-1].empty()) { // query while(dq[j-1].size() >= 2) { line a = dq[j-1][0]; line b = dq[j-1][1]; if(a.eval(pref[i]) < b.eval(pref[i])) dq[j-1].pop_front(); else break; } dp[i][j] = {dq[j-1].front().eval(pref[i]), dq[j-1].front().id}; // update line nl = {pref[i], dp[i][j][0] - pref[i]*pref[i], i}; while(dq[j].size() >= 2) { line a = dq[j][dq[j].size()-1]; line b = dq[j][dq[j].size()-2]; if(nl.m == a.m or isect(nl, a) <= isect(nl, b)) dq[j].pop_back(); else break; } dq[j].pb(nl); } cout << dp[n][k][0] << endl; int x = n; int l = k; while(dp[x][l][1] != 0) { x = dp[x][l][1]; l--; cout << x << " "; } cout << endl; } signed main() { fast_io; int t = 1; //cin >> t; while(t--) solve(); return 0; }

Compilation message (stderr)

sequence.cpp:44:16: error: 'k' was not declared in this scope
   44 | deque<line> dq[k+1];
      |                ^
sequence.cpp:45:7: error: 'n' was not declared in this scope; did you mean 'yn'?
   45 | ii dp[n+1][k+1];
      |       ^
      |       yn
sequence.cpp:45:12: error: 'k' was not declared in this scope
   45 | ii dp[n+1][k+1];
      |            ^
sequence.cpp: In function 'void solve()':
sequence.cpp:57:5: error: 'dq' was not declared in this scope; did you mean 'pq'?
   57 |     dq[0].pb({0, 0, 0});
      |     ^~
      |     pq
sequence.cpp:58:18: error: 'dp' was not declared in this scope
   58 |     loop(i, k+1) dp[0][i] = {0, 0};
      |                  ^~
sequence.cpp:68:9: error: 'dp' was not declared in this scope
   68 |         dp[i][j] = {dq[j-1].front().eval(pref[i]), dq[j-1].front().id};
      |         ^~
sequence.cpp:81:13: error: 'dp' was not declared in this scope
   81 |     cout << dp[n][k][0] << endl;
      |             ^~