Submission #1232841

#TimeUsernameProblemLanguageResultExecution timeMemory
1232841Tenis0206Building Skyscrapers (CEOI19_skyscrapers)C++20
54 / 100
368 ms50924 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 2e5; int n, T; int r[nmax + 5], c[nmax + 5]; bool sel[nmax + 5]; map<pair<int,int>, int> t; int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; void dfs_check(int nod) { sel[nod] = true; int x = r[nod]; int y = c[nod]; for(int p=0; p<8; p++) { int xx = x + dx[p]; int yy = y + dy[p]; int son = t[ {xx, yy}]; if(son == 0) { continue; } if(sel[son]) { continue; } dfs_check(son); } } int main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef home freopen("nr.in","r",stdin); freopen("nr.out","w",stdout); #endif cin>>n; cin>>T; int poz = 1; for(int i=1; i<=n; i++) { cin>>r[i]>>c[i]; t[ {r[i], c[i]}] = i; if(r[i] < r[poz] || (r[i] == r[poz] && c[i] < c[poz])) { poz = i; } } dfs_check(1); for(int i=1; i<=n; i++) { if(!sel[i]) { cout<<"NO\n"; return 0; } sel[i] = false; } priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> h; h.push({r[poz], c[poz]}); sel[poz] = true; vector<int> rez; while(!h.empty()) { int x = h.top().first; int y = h.top().second; int nod = t[ {x, y}]; h.pop(); rez.push_back(nod); for(int p=0; p<8; p++) { int xx = x + dx[p]; int yy = y + dy[p]; int son = t[ {xx, yy}]; if(son == 0) { continue; } if(sel[son]) { continue; } sel[son] = true; h.push({r[son], c[son]}); } } cout<<"YES\n"; for(auto it : rez) { cout<<it<<'\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...
#Verdict Execution timeMemoryGrader output
Fetching results...