Submission #1028955

#TimeUsernameProblemLanguageResultExecution timeMemory
1028955AmirAli_H1Ancient Books (IOI17_books)C++17
0 / 100
0 ms348 KiB
// In the name of Allah #include <bits/stdc++.h> #include "books.h" using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<ld> cld; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define kill(x) cout << x << '\n', exit(0) #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 1e6 + 4; int n; ll res; int A[maxn], mark[maxn]; void dfs(int v) { mark[v] = 1; if (!mark[A[v]]) dfs(A[v]); } ll minimum_walk(vector<int> p, int s) { n = len(p); res = 0; for (int i = 0; i < n; i++) { A[i] = p[i]; res += abs(i - A[i]); } int mx = 0; for (int i = 0; i < n; i++) { if (!mark[i]) { dfs(i); mx = max(mx, i); } } res += mx * 2; return res; }
#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...