Submission #120036

#TimeUsernameProblemLanguageResultExecution timeMemory
120036dsjongAncient Books (IOI17_books)C++14
22 / 100
262 ms32160 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; bool vis[1005]; long long minimum_walk(vector<int> p, int s) { vector<pair<int,int>>v; int n=p.size(); long long ans=0; for(int i=0;i<n;i++){ ans+=abs(i-p[i]); v.push_back({min(i,p[i]),max(i,p[i])}); } sort(v.begin(),v.end()); int last=0; for(auto i:v){ for(int j=max(last+1,i.first+1);j<=i.second;j++){ vis[j]=true; last=max(last,i.second); } } int k=-1; for(int i=n-1;i>=0;i--){ if(p[i]!=i){ k=i; break; } } k++; for(int i=1;i<k;i++){ if(!vis[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...