제출 #390978

#제출 시각아이디문제언어결과실행 시간메모리
390978alishahali1382고대 책들 (IOI17_books)C++14
50 / 100
146 ms22724 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--; for (int i=1; i<n; i++) ps[i]+=ps[i-1]; for (int i=0; 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...