Submission #597211

#TimeUsernameProblemLanguageResultExecution timeMemory
597211Valaki2Building Skyscrapers (CEOI19_skyscrapers)C++14
22 / 100
3594 ms8112 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define pii pair<int, int> #define fi first #define se second const vector<pii > dir = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; const vector<pii > dir_2 = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}}; int n, type; vector<pair<int, int> > v; unordered_map<int, unordered_map<int, int> > which; vector<int> ans; set<int> doable; bool has_neighbour(pii cur) { for(pii d : dir) { pii nei = mp(cur.fi + d.fi, cur.se + d.se); int nei_idx = which[nei.fi][nei.se]; if(nei_idx != 0) { return true; } } return false; } int count_bfs(int start, int miss) { queue<int> q; vector<bool> vis(1 + n, false); q.push(start); vis[start] = true; while(!q.empty()) { int cur = q.front(); q.pop(); for(pii d : dir) { pii nei = mp(v[cur].fi + d.fi, v[cur].se + d.se); int nei_idx = which[nei.fi][nei.se]; if(nei_idx != 0 && !vis[nei_idx] && nei_idx != miss) { q.push(nei_idx); vis[nei_idx] = true; } } } int res = 0; for(int i = 1; i <= n; i++) { if(vis[i]) { res++; } } return res; } queue<pii> q; unordered_map<int, unordered_map<int, bool> > seen; void upd_bfs() { while(!q.empty()) { pii cur = q.front(); q.pop(); for(pii d : dir_2) { pii nei = mp(cur.fi + d.fi, cur.se + d.se); int nei_idx = which[nei.fi][nei.se]; if(nei_idx != 0) { doable.insert(nei_idx); } else { if(!seen[nei.fi][nei.se] && has_neighbour(nei)) { q.push(nei); seen[nei.fi][nei.se] = true; } } } } } void solve() { cin >> n >> type; v.assign(1 + n, mp(0, 0)); int bottom_left = 1; for(int i = 1; i <= n; i++) { cin >> v[i].fi >> v[i].se; which[v[i].fi][v[i].se] = i; if(v[i].fi < v[bottom_left].fi) { bottom_left = i; } } if(count_bfs(1, -1) < n) { cout << "NO\n"; return; } cout << "YES\n"; set<int> rem; for(int i = 1; i <= n; i++) { rem.insert(i); } pii start = mp(v[bottom_left].fi - 1, v[bottom_left].se); q.push(start); seen[start.fi][start.se] = true; upd_bfs(); while(!doable.empty()) { int to_rem = -1; for(int cur : doable) { int st = *rem.begin(); if(st == cur) { st = *rem.rbegin(); } if(count_bfs(st, cur) >= (int) rem.size() - 1) { // cur can be removed to_rem = cur; break; } } ans.pb(to_rem); rem.erase(to_rem); doable.erase(to_rem); q.push(v[to_rem]); which[v[to_rem].fi][v[to_rem].se] = 0; upd_bfs(); } reverse(ans.begin(), ans.end()); for(int cur : ans) { cout << cur << "\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...