Submission #299747

#TimeUsernameProblemLanguageResultExecution timeMemory
299747errorgornAncient Books (IOI17_books)C++14
50 / 100
186 ms16120 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<int,int> #define fi first #define se second #define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() int n; vector<int> arr; int fwd[1000005]; long long minimum_walk(std::vector<int> p, int s) { n=sz(p); arr=p; rep(x,0,n){ if (x<arr[x]) fwd[x]++,fwd[arr[x]]--; } rep(x,0,n) fwd[x+1]+=fwd[x]; int l=0,r=n-1; while (l<s && fwd[l]==0) l++; while (s<=r && fwd[r]==0) r--; ll ans=0; rep(x,l,r+1){ ans+=max(fwd[x],1); } return ans*2; }
#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...