제출 #526855

#제출 시각아이디문제언어결과실행 시간메모리
526855KoD고대 책들 (IOI17_books)C++17
50 / 100
108 ms18892 KiB
#include <bits/stdc++.h> #include "books.h" using std::vector; using std::array; using std::pair; using std::tuple; using ll = long long; ll minimum_walk(vector<int> P, int src) { assert(src == 0); if (std::is_sorted(P.begin(), P.end())) { return 0; } while (P.back() == (int)P.size() - 1) { P.pop_back(); } const int N = P.size(); vector<int> coeff(N); ll ret = 0; for (int i = 0; i < N; ++i) { const int x = std::min(i, P[i]); const int y = std::max(i, P[i]); coeff[x] += 1; coeff[y] -= 1; ret += y - x; } for (int i = 0; i < N - 1; ++i) { if (coeff[i] == 0) { ret += 2; } coeff[i + 1] += coeff[i]; } return ret; }
#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...