Submission #1037578

#TimeUsernameProblemLanguageResultExecution timeMemory
1037578HappyCapybaraAncient Books (IOI17_books)C++17
50 / 100
85 ms19028 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; #define ll long long ll minimum_walk(vector<int> p, int s){ int n = p.size(); ll d = 0; int nt = 0; for (int i=0; i<n; i++){ if (p[i] != i) nt++; d += abs(p[i]-i); } ll e = 0; vector<int> q(n); for (int i=0; i<n; i++) q[p[i]] = i; int l = 0, r = 0, cur = 0; while (l < n){ r = max(r, max(p[l], q[l])); if (p[l] != l) cur++; if (l == r && cur != nt) e++; l++; } return d + 2*e; }
#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...