제출 #289221

#제출 시각아이디문제언어결과실행 시간메모리
289221wdjpng고대 책들 (IOI17_books)C++17
0 / 100
1 ms256 KiB
#include <bits/stdc++.h> #include "books.h" #define rep(i,n) for(int i = 0; i < n; i++) #define lint long long using namespace std; vector<int>P; vector<bool>vis; int dfs(int v) { if(vis[v]) return 0; vis[v]=true; return abs(v - P[v]) + dfs(P[v]); } long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); vis.resize(n); P=p; int count=0; int numComp=0; rep(i, n) { if(vis[i]){continue;} numComp++; count+=dfs(i); } return count+2*(numComp-1); }
#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...