답안 #427013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427013 2021-06-14T11:47:49 Z Hazem 고대 책들 (IOI17_books) C++14
0 / 100
219 ms 288 KB
#include "books.h"
#include <bits/stdc++.h>
#define LL long long 

using namespace std;

const LL LINF  = 1e18;

int a[10],n;
vector<int>vec;

bool check(){

	bool q = 1;
	for(int i=0;i<n;i++)
		q &= (a[i]==vec[i]);
	
	return q;
}

LL bt(int pos,int cur,int cnt);

LL move(int pos,int cur,int cnt){

	LL ret = LINF;

	if(pos<n-1)
		ret = min(ret,bt(pos+1,cur,cnt+1));
	
	if(pos>0)
		ret = min(ret,bt(pos-1,cur,cnt+1));

	return ret;
}

LL bt(int pos,int cur,int cnt){

	if((cur==-1)&&!pos&&check())
		return cnt;
	
	if(cnt>12)
		return LINF;

	LL ret = LINF;
	ret = min(ret,move(pos,cur,cnt));
	
	if(cur==-1){
		cur = a[pos];
		a[pos] = -1;
		ret=  min(ret,move(pos,cur,cnt));
		a[pos] = cur;
		cur = -1;
	}

	if(a[pos]==-1){
		a[pos] = cur;
		cur = -1;
		ret = min(ret,move(pos,cur,cnt));
		cur = a[pos];
		a[pos] = -1;
	}

	if(cur>=0&&a[pos]>=0){
		swap(cur,a[pos]);
		ret = min(ret,move(pos,cur,cnt));
		swap(cur,a[pos]);
	}

	return ret;
}

long long minimum_walk(std::vector<int> P, int s) {	
	
	vec = P;
	n = P.size();
	for(int i=0;i<n;i++)
		a[i] = i;
		
	return bt(0,-1,0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 204 KB Output is correct
2 Correct 26 ms 204 KB Output is correct
3 Incorrect 27 ms 284 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 204 KB Output is correct
2 Correct 26 ms 204 KB Output is correct
3 Incorrect 27 ms 284 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 204 KB Output is correct
2 Correct 26 ms 204 KB Output is correct
3 Incorrect 27 ms 284 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 219 ms 288 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 204 KB Output is correct
2 Correct 26 ms 204 KB Output is correct
3 Incorrect 27 ms 284 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -