Submission #1055634

#TimeUsernameProblemLanguageResultExecution timeMemory
1055634aaaaaarrozAncient Books (IOI17_books)C++17
50 / 100
81 ms18916 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; long long minimum_walk(vector<int> p, int s) { int n = p.size(); vector mover(n,0); int last_voilater = 0; long long ans = 0; for(int i=0;i<n;i++) { if(p[i]==i)continue; ans+=abs(p[i]-i); last_voilater=i; mover[min(p[i],i)]++; mover[max(p[i],i)]--; } for(int i=1;i<n;i++)mover[i]+=mover[i-1]; for(int i=0;i<last_voilater;i++) { if(mover[i]==0)ans+=2; } return ans; }
#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...