Submission #1034931

#TimeUsernameProblemLanguageResultExecution timeMemory
1034931vjudge1Ancient Books (IOI17_books)C++17
0 / 100
0 ms348 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; int par[100100]; int abp(int n){ return par[n]?par[n]=abp(par[n]):n; } int merge(int a,int b){ a=abp(a+1);b=abp(b+1); if(a-b)par[a]=b; return a!=b; } long long minimum_walk(std::vector<int> p, int s) { long long ans=0; int n=p.size(),K=0; for(int i=0;i<n;i++)if(i-p[i]) K=i, ans+=abs(i-p[i]),merge(i,p[i]); for(int i=1;i<=K;i++) ans+=2*merge(i-1,i); 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...