Submission #390980

#TimeUsernameProblemLanguageResultExecution timeMemory
390980alishahali1382Ancient Books (IOI17_books)C++14
50 / 100
172 ms15940 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; #define debug(x) {cerr<<#x<<"="<<x<<"\n";} #define debug2(x, y) {cerr<<#x<<", "<<#y<<" = "<<x<<", "<<y<<"\n";} #define pb push_back #define all(x) x.begin(), x.end() const int inf=1000000100; const int MAXN=1000010; ll ans; // :) int n, m, k, s; int P[MAXN], A[MAXN], ps[MAXN]; ll minimum_walk(vector<int> _p, int s){ n=_p.size(); for (int i=0; i<n; i++){ P[i]=_p[i]; ans+=abs(i-P[i]); ps[min(i, P[i])]++; ps[max(i, P[i])]--; } if (!ans) return 0; while (P[n-1]==n-1) n--; int L=0; while (L<s && A[L]==L) L++; for (int i=1; i<n; i++) ps[i]+=ps[i-1]; for (int i=L; i+1<n; i++) if (!ps[i]) 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...