Submission #1242507

#TimeUsernameProblemLanguageResultExecution timeMemory
1242507iyedooArranging Shoes (IOI19_shoes)C++20
10 / 100
1096 ms12100 KiB
#include "shoes.h"

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n;
vector<int> config;

ll mn = LLONG_MAX;

void shoes(int i, ll swaps) {
	if (i == n - 1) {
		// for (int x: config) cout << x << " ";
		// cout << "\n";

		bool valid = true;
		for (int i = 0; i < n; i += 2) {
			if (abs(config[i]) != config[i + 1]) {
				valid = false;
				break;
			}
		}

		if (valid) mn = min(mn, swaps);

		return;
	}

	swap(config[i], config[i + 1]);
	shoes(i + 1, swaps + 1);
	swap(config[i], config[i + 1]);
	shoes(i + 1, swaps);
}

ll count_swaps(vector<int> s) {
	n = s.size();
	config = s;

	shoes(0, 0);


	return mn;	
}
#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...