Submission #1052426

#TimeUsernameProblemLanguageResultExecution timeMemory
1052426mansurAncient Books (IOI17_books)C++17
0 / 100
1 ms348 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; #define rall(s) s.rbegin(), s.rend() #define all(s) s.begin(), s.end() #define sz(s) (int)s.size() #define s second #define f first using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int N = 3e5; ll minimum_walk(vector<int> p, int s) { int n = sz(p), mx = 0; vector<int> was(n + 1); ll ans = 0; for (int i = 0; i < n; i++) { if (was[i] || i == p[i]) continue; int x = i, mn = n; while (!was[x]) { mn = min(mn, x); was[x] = 1; ans += abs(p[x] - x); x = p[x]; } mx = max(mx, mn); } ans += (mx - s) * 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...