Submission #782254

#TimeUsernameProblemLanguageResultExecution timeMemory
782254ikaurovAncient Books (IOI17_books)C++17
Compilation error
0 ms0 KiB
long long minimum_walk(std::vector<int> p, int s) { int n = sz(p); ll ans = 0; vector<int> x{0}, sx{0}, sumsz{0}; for (int i = 0; i < n; i++){ ans += abs(i - p[i]); } for (int i = 0, mx = -1; i < n;){ if (i == p[i] && mx < i){ int j = i; while (j < n && j == p[j]) j++; if (j == n) break; x.pb(j - i); sx.pb(sx.back() + x.back()); sumsz.pb(j); i = j; } else mx = max(mx, p[i]), i++; } x.pb(0); sx.pb(sx.back()); sumsz.pb(sumsz.back()); int m = sz(x); vector<ll> dp(m); ll minval = 0; for (int i = 1; i < m; i++){ dp[i] = minval + sx[i - 1] * 2 + sumsz[i] + x[i]; minval = min(minval, dp[i] - 2 * sx[i] - sumsz[i]); } return ans + dp.back(); }

Compilation message (stderr)

books.cpp:1:29: error: 'vector' is not a member of 'std'
    1 | long long minimum_walk(std::vector<int> p, int s) {
      |                             ^~~~~~
books.cpp:1:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
  +++ |+#include <vector>
    1 | long long minimum_walk(std::vector<int> p, int s) {
books.cpp:1:36: error: expected primary-expression before 'int'
    1 | long long minimum_walk(std::vector<int> p, int s) {
      |                                    ^~~
books.cpp:1:44: error: expected primary-expression before 'int'
    1 | long long minimum_walk(std::vector<int> p, int s) {
      |                                            ^~~
books.cpp:1:49: error: expression list treated as compound expression in initializer [-fpermissive]
    1 | long long minimum_walk(std::vector<int> p, int s) {
      |                                                 ^