이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include<bits/stdc++.h>
#define ii pair<int,int>
#define st first
#define nd second
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long
#define sz(x) ((int)x.size())
using namespace std;
long long minimum_walk(std::vector<int> p, int s) {
if(s!=0) return 12312;
ll ans=0;
int n=sz(p);
int last=0;
while(1) {
int go=-1;
for(int i=0;i<n;i++) {
if(p[i]>i) {
go=i;
break ;
}
}
if(go==-1) break ;
ans+=go-last;
s=go;
last=go;
int hand=p[s];
p[s]=-1;
int way=0;
s++;
while(1) {
/*for(int i=0;i<n;i++) cerr<<p[i]<<' ';
cerr<<endl;
cerr<<"way is-->"<<way<<endl<<"hand is-->"<<hand<<endl<<"s is-->"<<s<<endl;
getchar();*/
if(way==0) {
if(hand==s) {
swap(hand,p[s]);
if(hand<s && hand!=-1) way=1;
else if(hand>s) way=0;
else break ;
}
if(p[s]>hand) swap(hand,p[s]);
s++;
}
else {
if(hand==s) {
swap(hand,p[s]);
if(hand<s && hand!=-1) way=1;
else if(hand>s) way=0;
else break ;
}
if(p[s]<hand) swap(hand,p[s]);
s--;
}
ans++;
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |