Submission #199688

#TimeUsernameProblemLanguageResultExecution timeMemory
199688MladenPAncient Books (IOI17_books)C++17
0 / 100
6 ms504 KiB
#include "books.h" #include<bits/stdc++.h> #define PRINT(x) cerr<<#x<<'='<<x<<endl; #define NL(x) " \n"[(x)] #define lld long long #define pil pair<int,lld> #define pli pair<lld,int> #define pll pair<lld,lld> #define pii pair<int,int> #define pb push_back #define fi first #define se second #define mid (l+r)/2 #define endl '\n' #define all(a) begin(a),end(a) #define sz(a) int((a).size()) #define LINF 1000000000000000LL #define INF 1000000000 #define EPS 1e-9 using namespace std; #define MAXN 1000010 int N, posl, pos[MAXN], a[MAXN]; void dfs(int node) { pos[node] = true; if(!pos[a[node]]) dfs(a[node]); } long long minimum_walk(std::vector<int> p, int s) { lld rez = 0; N = sz(p); for(int i = 0; i < N; i++) a[i] = p[i], rez += abs(p[i]-i); for(int i = 0; i < N; i++) { if(!pos[i]) { posl = i; dfs(i); } } rez += 2*posl; return rez; }
#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...