제출 #120463

#제출 시각아이디문제언어결과실행 시간메모리
120463tinjyu고대 책들 (IOI17_books)C++14
22 / 100
2045 ms15992 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; bool tag[1000005]; int a[1000005]; long long int ans; long long minimum_walk(std::vector<int> p, int s) { long long int n=p.size(),ans=0; int l=n+1,r=-1; int c=0; for(int i=0;i<n;i++) { ans+=abs(i-p[i]); if(i<p[i]) { c=1; for(int j=i;j<p[i];j++)tag[j]=1; l=min(i,l); r=max(p[i]-1,r); } if(i>p[i]) { c=1; for(int j=p[i];j<i;j++)tag[j]=1; l=min(p[i],l); r=max(i-1,r); } } for(int i=min(s,l);i<=max(s,r);i++) { if(tag[i]==0)ans+=2; } if(c==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...