제출 #1213483

#제출 시각아이디문제언어결과실행 시간메모리
1213483repsak고대 책들 (IOI17_books)C++20
12 / 100
2095 ms328 KiB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll MAX = 1e18;

int veri(vector<int>& ajusted){
	int N = ajusted.size();
	for(int i = 0; i < N; i++){
		if(ajusted[i] != i) return 0;
	}
	
	return 1;
}

ll gen(int index, vector<int>& values, ll cost, ll& best, int holding){
	if(index < 0 || index >= values.size()) return MAX;
	if(cost >= best) return MAX;
	if(index == 0){
		if(veri(values)){
			best = min(cost, best);
			return min(cost, best);
		}
	}

	if(values[index] == -1){
		values[index] = holding;
		gen(index, values, cost, best, -1);
		values[index] = -1;
	}

	gen(index + 1, values, cost + 1, best, holding);
	gen(index - 1, values, cost + 1, best, holding);

	int valI = values[index];
	values[index] = holding;
	gen(index + 1, values, cost + 1, best, valI);
	values[index] = valI;
	
	int valE = values[index];
	values[index] = holding;
	gen(index - 1, values, cost + 1, best, valE);
	values[index] = valE;
	return best;
}

long long minimum_walk(vector<int> p, int s) {
	ll val = 16;
	return gen(0, p, 0, val, -1);
}

// #include "grader.cpp"
#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...