제출 #946399

#제출 시각아이디문제언어결과실행 시간메모리
946399MinaRagy06Parking (CEOI22_parking)C++17
0 / 100
2089 ms8660 KiB
#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 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...