제출 #1225408

#제출 시각아이디문제언어결과실행 시간메모리
1225408walizamanee고대 책들 (IOI17_books)C++20
50 / 100
101 ms12104 KiB
#include<bits/stdc++.h> #include "books.h" using namespace std; using ll = long long; int here[2000001] , one , two , boro; 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; boro = 0; for( int z = s; z < n; z++ ) { if( here[z] == 0 && p[z] != z ) { //ans += (ll)(2) * (ll)(abs(one - z)); if( boro < z ) ans += (z - boro) + (z - boro); two = z; while(here[two] == 0 ) { boro = max( boro , two ); 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...