제출 #1215793

#제출 시각아이디문제언어결과실행 시간메모리
1215793AblablaArranging Shoes (IOI19_shoes)C++20
0 / 100
1094 ms320 KiB
#include "shoes.h"
#include <bits/stdc++.h>

using namespace std;

long long count_swaps(vector<int> s) {
	int n = s.size() / 2;

	vector<int> index;
	for(int i = 0; i < 2*n; i++){
		if(s[i] < 0){
			index.push_back(i);
		}
	}

	vector<int> mas = s;
	int ans = 0;

	for(int i = 0; i < n; i++){
		int keres = s[index[i]];
		int ind = 0;
		for(int j = 2*i; j < 2*n; j++){
			if(mas[j] == keres){
				ind = j;
				break;
			}
		}

		while(ind > 2*i){
			swap(mas[ind - 1], mas[ind]);
			ans++;
			ind--;
		}

		keres *= -1;
		ind = 0;
		for(int j = 2*i + 1; j < 2*n; j++){
			if(mas[j] == keres){
				ind = j;
				break;
			}
		}

		while(ind > 2*i + 1){
			swap(mas[ind - 1], mas[ind]);
			ans++;
			ind--;
		}
	}


	while(!next_permutation(index.begin(), index.end())){
		vector<int> mas = s;
		int akt = 0;

		for(int i = 0; i < n; i++){
			int keres = s[index[i]];
			int ind = 0;
			for(int j = 2*i; j < 2*n; j++){
				if(mas[j] == keres){
					ind = j;
					break;
				}
			}

			while(ind > 2*i){
				swap(mas[ind - 1], mas[ind]);
				akt++;
				ind--;
			}

			keres *= -1;
			ind = 0;
			for(int j = 2*i + 1; j < 2*n; j++){
				if(mas[j] == keres){
					ind = j;
					break;
				}
			}

			while(ind > 2*i + 1){
				swap(mas[ind - 1], mas[ind]);
				akt++;
				ind--;
			}
		}

		ans = min(ans, akt);
	}

	return ans;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...