Submission #620005

#TimeUsernameProblemLanguageResultExecution timeMemory
620005OzyAncient Books (IOI17_books)C++17
50 / 100
153 ms30600 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; #define lli long long int #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define MAX 1000000 lli n,ini,fin,res,last,activos,a,act; lli vis[MAX+2]; vector<pair<lli,lli> > eventos; long long minimum_walk(std::vector<int> p, int s) { n = p.size(); res = 0; rep(i,0,n-1) { if (vis[i]) continue; if (p[i] == i) continue; vis[i] = 1; ini = i; fin = i; act = p[i]; res += abs(i - act); while (act != i) { vis[act] = 1; ini = min(ini,act); fin = max(fin,act); res += abs(p[act] - act); act = p[act]; } eventos.push_back({ini,0}); eventos.push_back({fin,1}); } sort(eventos.begin(), eventos.end()); last = 0; activos = 0; for (auto e : eventos) { if (activos == 0) { a = e.first - last; a *= 2; res += a; } last = e.first; if (e.second) activos--; else activos++; } return res; }
#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...