Submission #1224916

#TimeUsernameProblemLanguageResultExecution timeMemory
1224916walizamaneeAncient Books (IOI17_books)C++20
0 / 100
0 ms328 KiB
#include<bits/stdc++.h> #include "books.h" using namespace std; using ll = long long; int here[2000001] , one , two; long long ans; long long minimum_walk(vector<int> p, int s) { int n = p.size(); for( int z = 0; z < n; z++ ) { here[z] = 0; } one = s; ans = 0; for( int z = s; z < n; z++ ) { if( here[z] == 0 && p[z] != z ) { ans += (ll)(2) * (ll)(abs(one - z)); two = z; while(here[two] == 0 ) { here[two] = 1; ans += (ll)(abs(two - p[two])); two = p[two]; } one = z; } } 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...