Submission #364615

#TimeUsernameProblemLanguageResultExecution timeMemory
364615rqiAncient Books (IOI17_books)C++14
0 / 100
1 ms364 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef long long ll; #define sz(x) (int)(x).size() long long minimum_walk(vi p, int s) { int n = sz(p); vi cover = vi(n, 0); vi dirover = vi(n, 0); //right = +1 ll ans = 0; for(int i = 0; i < n; i++){ cover[min(i, p[i])]++; cover[max(i, p[i])]--; dirover[i]++; dirover[p[i]]--; ans+=abs(p[i]-i); } //cout << ans << "\n"; for(int i = 1; i < n; i++){ cover[i]+=cover[i-1]; dirover[i]+=dirover[i-1]; } for(int i = 0; i < n; i++){ ans+=abs(dirover[i]); } for(int i = 0; i < n-1; i++){ if(cover[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...