Submission #946399

# Submission time Handle Problem Language Result Execution time Memory
946399 2024-03-14T15:55:27 Z MinaRagy06 Parking (CEOI22_parking) C++17
0 / 100
2000 ms 8660 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, m;
	cin >> n >> m;
	int v[m][2];
	set<int> s;
	int col[n + 1]{};
	memset(col, -1, sizeof col);
	for (int i = 0; i < m; i++) {
		cin >> v[i][0] >> v[i][1];
		if (!v[i][0]) {
			s.insert(i);
		} else if (!v[i][1]) {
			col[v[i][0]] = i;
		}
	}
	vector<array<int, 2>> ans;
	for (int i = 0; i < m; i++) {
		if (v[i][0] == v[i][1]) continue;
		if (v[i][1]) {
			if (col[v[i][1]] != -1) {
				ans.push_back({i, col[v[i][1]]});
				v[col[v[i][1]]][1] = v[i][1];
				v[i][1] = 0;
			} else {
				int x = *s.begin();
				s.erase(s.begin());
				ans.push_back({i, x});
				v[x][0] = v[i][1];
				col[v[i][1]] = x;
				v[i][1] = 0;
			}
		}
		if (v[i][0]) {
			if (col[v[i][0]] == -1) {
				col[v[i][0]] = i;
			} else if (col[v[i][0]] != i) {
				ans.push_back({i, col[v[i][0]]});
				v[col[v[i][0]]][1] = v[i][0];
				v[i][0] = 0;
			}
		}
	}
	cout << ans.size() << '\n';
	for (auto [x, y] : ans) {
		cout << x + 1 << ' ' << y + 1 << '\n';
	}
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 2032 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 8660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2089 ms 352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2089 ms 352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2036 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 2032 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -