Submission #132794

#TimeUsernameProblemLanguageResultExecution timeMemory
132794TalantAncient Books (IOI17_books)C++17
0 / 100
2 ms376 KiB
#include "books.h" #include <bits/stdc++.h> #define sc second #define fr first #define mk make_pair #define pb push_back using namespace std; const int N = (1e6 + 5); const int inf = (1e9 + 7); int a[N]; int u[N]; int n; long long ans; long long minimum_walk(vector<int> p, int s) { n = p.size(); s ++; for (int i = 0; i < n; i ++) a[i + 1] = p[i] + 1,ans += abs(p[i] - i); int last = s; for (int i = 1; i <= n; i ++) { if (a[i] > i) { for (int j = i + 1; j <= last; j ++) { if (a[j] < j && i < a[j] && a[j] < last) { ans -= abs(a[j] - j); u[j] = 1; } } ans += abs(last - i); last = a[i]; } } for (int i = n; i >= 1; i --) { if (i > a[i] && u[i] == 0) { ans += abs(last - i); last = a[i]; } } return (ans + abs(s - last)); }
#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...