답안 #427096

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

using namespace std;

const LL LINF  = 1e18;

int n;
vector<int>vec,a;
map<vector<int>,LL>mp;

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);

LL move(int pos,int cur){

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

	return ret;
}

LL bt(int pos,int cur){

	vector<int> state = a;
	state.push_back(pos);
	state.push_back(cur);

	if(!pos&&check())
		return 0;
	
	if(mp.find(state)!=mp.end())
		return mp[state];
	
	mp[state] = LINF;

	LL ret = LINF;
	ret = min(ret,move(pos,cur));
	
	swap(cur,a[pos]);
	ret = min(ret,move(pos,cur));
	swap(cur,a[pos]);

	return mp[state] = ret;
}

long long minimum_walk(std::vector<int> P, int s) {	
	
	a = P;
	n = P.size();
	for(int i=0;i<n;i++)
		vec.push_back(i);

	return bt(0,-1);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2097 ms 416220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -