# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
59658 | TadijaSebez | Ancient Books (IOI17_books) | C++11 | 330 ms | 243252 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
queue<int> q1,q2;
const int N=1000050;
int max(int a, int b){ return a>b?a:b;}
int min(int a, int b){ return a>b?b:a;}
int abs(int x){ return x>0?x:-x;}
ll minimum_walk(vector<int> p, int s)
{
ll sol=0;
int n=p.size(),i,j,ml=n,mr=-1;
for(i=0;i<n;i++)
{
sol+=abs(p[i]-i);
if(p[i]!=i) ml=min(ml,i),mr=max(mr,i);
}
q1.push(s);
int myl=s,myr=s;
while(1)
{
while(q1.size())
{
int x=q1.front();q1.pop();
while(myl>p[x]) q1.push(--myl);
while(myr<p[x]) q1.push(++myr);
}
int nl=myl,nr=myr,addl=0,addr=0;
bool lf=0,rf=0;
while(1)
{
if(nl<=ml) break;
nl--;addl+=2;q2.push(nl);
while(q2.size())
{
int x=q2.front();q2.pop();
if(p[x]>s) lf=1;
while(nl>p[x]) q2.push(--nl);
}
if(lf) break;
}
while(1)
{
if(nr>=mr) break;
nr++;addr+=2;q2.push(nr);
while(q2.size())
{
int x=q2.front();q2.pop();
if(p[x]<s) rf=1;
while(nr<p[x]) q2.push(++nr);
}
if(rf) break;
}
if(lf && rf) sol+=min(addl,addr);
else{ sol+=addl+addr;break;}
while(myl>nl) q1.push(--myl);
while(myr<nr) q1.push(++myr);
}
return sol;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |