답안 #691516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
691516 2023-01-31T08:08:22 Z Sohsoh84 Parking (CEOI22_parking) C++17
10 / 100
2 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 20 + 10;

int n, m, A[MAXN][2], B[MAXN][2];
vector<pll> fans;
vector<int> vec;

inline vector<pll> solve() {
	vector<pll> ans;
	for (int i : vec) {
		bool flag = true;
		for (int j = 1; j <= m; j++)
			flag &= (B[j][0] == B[j][1]);
		if (flag) break;

		if (!B[i][0]) continue;
		
		int emp_col = 0;
		for (int j = 1; j <= m; j++)
			if (!B[j][0]) emp_col = j;

		int ind = 1;
		if (!B[i][1]) ind = 0;
		
		int x = B[i][ind];
		for (int j = 1; j <= m; j++) {
			if (j == i) continue;
			if (B[j][1] == 0 && B[j][0] == x) emp_col = j;
		}

		if (!emp_col) continue;
		B[i][ind] = 0;

		if (!B[emp_col][0]) B[emp_col][0] = x;
		else B[emp_col][1] = x;
		ans.push_back({i, emp_col});	
	}


	bool flag = true;
	for (int j = 1; j <= m; j++)
		flag &= (B[j][0] == B[j][1]);
	if (flag) return ans;
	return fans;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> A[i][0] >> A[i][1];
		vec.push_back(i);
		vec.push_back(i);
	}

	for (int i = 0; i < MAXN * MAXN; i++) fans.push_back({0, 0});

	do {
		for (int i = 1; i <= m; i++) B[i][0] = A[i][0], B[i][1] = A[i][1];
		vector<pll> tans = solve();
		if (tans.size() < fans.size()) fans = tans;
	} while (next_permutation(all(vec)));

	if (fans.size() >= MAXN * MAXN) return cout << -1 << endl, 0;
	cout << fans.size() << endl;
	for (auto [x, y] : fans)
		cout << x << sep << y << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 2 ms 324 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 2 ms 324 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Runtime error 1 ms 468 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -