제출 #691537

#제출 시각아이디문제언어결과실행 시간메모리
691537Sohsoh84Parking (CEOI22_parking)C++17
10 / 100
1 ms468 KiB
#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 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...