Submission #892428

#TimeUsernameProblemLanguageResultExecution timeMemory
892428abcvuitunggioAncient Books (IOI17_books)C++17
0 / 100
0 ms348 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; int vis[1000001],r[1000001]; vector <pair <int, pair <int, int>>> e; long long minimum_walk(vector <int> p, int s){ int x=0,n=p.size(); vector <pair <int, int>> tmp; long long d=0; for (int i=0;i<n;i++){ if (!vis[i]){ int x=i; while (true){ vis[x]=1; r[i]=max(r[i],x); d+=abs(x-p[x]); x=p[x]; if (x==i) break; } if (r[i]!=x||i) tmp.push_back({i,r[i]}); } } sort(tmp.begin(),tmp.end()); int cur=0; for (auto [l,r]:tmp){ x+=max(l-cur,0); cur=max(cur,r); } return x*2+d; }
#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...