Submission #1053004

#TimeUsernameProblemLanguageResultExecution timeMemory
1053004abczzAncient Books (IOI17_books)C++17
50 / 100
64 ms15184 KiB
#include "books.h" #include <iostream> #define ll long long using namespace std; long long minimum_walk(std::vector<int> p, int s) { ll n = p.size(), l, r, x, y, f = 0, mx = 0; for (int i=0; i<n; ++i) { f += abs(i-p[i]); } l = n, r = -1; for (int i=0; i<n; ++i) { if (p[i] != i) { l = i; break; } } for (int i=n-1; i>=0; --i) { if (p[i] != i) { r = i; break; } } if (l == n) return 0; x = y = s; while (true) { if (x < n && x != p[x]) break; if (y >= 0 && y != p[y]) break; ++x, --y; f += 2; } for (int i=l; i<=r; ++i) { mx = max(mx, (ll)p[i]); if (mx == i) f += 2; } f -= 2; return f; }
#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...