Submission #1060857

#TimeUsernameProblemLanguageResultExecution timeMemory
1060857onbertAncient Books (IOI17_books)C++17
12 / 100
1 ms2396 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; #define int long long struct thing { int u, v, w; bool operator < (const thing &b) const { return w < b.w; } }; const int maxn = 1e6 + 5, INF = 1e9; int vis[maxn]; int last[maxn]; int minimum_walk(vector<int32_t> p, int32_t s) { int n = p.size(); for (int i=0;i<n;i++) vis[i] = false; int ans = 0; vector<pair<int,int>> vec; for (int i=0;i<n;i++) if (!vis[i]) { if (p[i]==i && i==s) { vec.push_back({s, s}); } if (p[i]==i) continue; int u = i; pair<int,int> val = {u, u}; while (true) { vis[u] = 1; val.first = min(u, val.first), val.second = max(u, val.second); int v = p[u]; ans += abs(v-u); if (v==i) break; u = v; } vec.push_back(val); } int sz = vec.size(); for (int i=1;i<sz;i++) { if (vec[i].first > vec[i-1].second) ans += (vec[i].first - vec[i-1].second)*2; } return ans; }
#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...