Submission #1076266

#TimeUsernameProblemLanguageResultExecution timeMemory
1076266mdn2002Ancient Books (IOI17_books)C++14
50 / 100
1828 ms89256 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; long long minimum_walk(std::vector<int> p, int s) { assert(s == 0); long long ans = 0, n = p.size(), stt = 0; set<int> st; map<int, int> mp; vector<int> b(n + 2); for (int i = 0; i < n; i ++) { if (p[i] != i) { ans += abs(i - p[i]); st.insert(p[i]); mp[p[i]] ++; mp[i] --; st.erase(i); } if (st.size() == 0 || *st.rbegin() <= i) b[i] = 1; } for (int i = n - 2; i >= 0; i --) { if (stt && b[i]) ans += 2; if (p[i] != i) stt = 1; } return ans; } /* 4 0 3 2 1 0 */
#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...