Submission #603222

#TimeUsernameProblemLanguageResultExecution timeMemory
603222mosiashvililukaAncient Books (IOI17_books)C++14
50 / 100
172 ms38332 KiB
#include<bits/stdc++.h> #include "books.h" using namespace std; long long a,b,c,d,e,i,j,ii,jj,zx,xc,f[1000009],S,bo[1000009],G[1000009],pas,mx; long long minimum_walk(std::vector<int> Pp, int Ss) { a=Pp.size();S=Ss+1; for(i=1; i<=a; i++) f[i]=Pp[i-1]+1; zx=1; for(i=1; i<=a; i++){ if(bo[i]==1) continue; c=i;mx=i; while(1){ bo[c]=1; G[i]+=abs(c-f[c]); mx=max(mx,c); c=f[c]; if(c==i) break; } pas+=G[i]; if(G[i]!=0){ if(zx<i){ pas+=(i-zx)*2LL; } zx=max(zx,mx); } } return pas; }
#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...