Submission #691537

# Submission time Handle Problem Language Result Execution time Memory
691537 2023-01-31T08:46:06 Z Sohsoh84 Parking (CEOI22_parking) C++17
10 / 100
1 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 = 1e2 + 10; // change this shit TODO

int n, m, A[MAXN][2];
vector<pll> ans;

inline int sz(int i) {
	return int(A[i][0] > 0) + int(A[i][1] > 0);
}

inline int emp_col() {
	for (int i = 1; i <= m; i++)
		if (!sz(i))
			return i;
	
	return 0;
}

inline void move(int i, int j) {
	A[j][sz(j)] = A[i][sz(i) - 1];
	A[i][sz(i) - 1] = 0;
	ans.push_back({i, j});
}

inline bool try_match() {
	for (int i = 1; i <= m; i++) {
		if (sz(i) != 1) continue;
		int x = A[i][0];
		for (int j = 1; j <= m; j++) {
			if (j == i || sz(j) == 0 || A[j][sz(j) - 1] != x) continue;
			move(j, i);
			return true;
		}
	}

	return false;
}

inline bool is_ok() {
	for (int i = 1; i <= m; i++)
		if (A[i][0] != A[i][1])
			return false;

	return true;
}

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];
	
	while (!is_ok()) {
		while (try_match()) {}
		int x = emp_col();
		if (!x) return cout << -1 << endl, 0;
		
		for (int i = 1; i <= n; i++) {
			if (sz(i) == 2 && A[i][0] != A[i][1]) {
				move(i, x);
				break;
			}
		}
	}

	if (!is_ok()) return cout << -1 << endl, 0;

	cout << ans.size() << endl;
	for (auto [i, j] : ans)
		cout << i << sep << j << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 456 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -