Submission #887108

#TimeUsernameProblemLanguageResultExecution timeMemory
887108MackerFlood (IOI07_flood)C++17
100 / 100
244 ms25232 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() vector<array<int, 4>> adj; vector<array<int, 4>> adji; vector<int> res; vector<int> vis; int strt = -1; bool dfs(int a, int dir, int r){ for (int i = -1; i < 3; i++) { int j = (i + dir + 4) % 4; int b = adj[a][j]; if(b == strt){ if(vis[adji[a][j]] == r) res.push_back(adji[a][j]); adj[a][j] = -1; adj[b][(j + 2) % 4] = -1; return 1; } if(b != -1){ if(vis[adji[a][j]] == r){ res.push_back(adji[a][j]); adj[a][j] = -1; adj[b][(j + 2) % 4] = -1; } vis[adji[a][j]] = r; vis[adji[b][(j + 2) % 4]] = r; if(dfs(b, j, r)){ adj[a][j] = -1; adj[b][(j + 2) % 4] = -1; return 1; } } } return 0; } int main() { int n; cin >> n; vector<array<int, 3>> pos(n); vector<int> pord(n); adj.resize(n, {-1, -1, -1, -1}); //up, left, down, right adji.resize(n, {-1, -1, -1, -1}); //up, left, down, right for (int i = 0; i < n; i++){ cin >> pos[i][0] >> pos[i][1]; pos[i][2] = i; } int w; cin >> w; vis.resize(w + 1, -1); for (int i = 1; i <= w; i++) { int a, b; cin >> a >> b; a--; b--; if(pos[a][1] == pos[b][1]){ if(pos[a][0] > pos[b][0]){ adj[a][0] = b; adj[b][2] = a; adji[a][0] = i; adji[b][2] = i; } else{ adj[a][2] = b; adj[b][0] = a; adji[a][2] = i; adji[b][0] = i; } } else{ if(pos[a][1] < pos[b][1]){ adj[a][3] = b; adj[b][1] = a; adji[a][3] = i; adji[b][1] = i; } else{ adj[a][1] = b; adj[b][3] = a; adji[a][1] = i; adji[b][3] = i; } } } sort(all(pos)); for (auto p : pos) { if(adj[p[2]] == array<int, 4>({-1, -1, -1, -1})) continue; for (int i = 0; i < 4; i++) { if(adj[p[2]][i] != -1){ strt = p[2]; dfs(p[2], i, p[2]); } } } cout << res.size() << endl; for (auto &&i : res) cout << i << endl; }
#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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...