Submission #247533

#TimeUsernameProblemLanguageResultExecution timeMemory
247533mieszko11bBuilding Skyscrapers (CEOI19_skyscrapers)C++14
0 / 100
3574 ms156108 KiB
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; #define X first #define Y second int n, t, cnt; map<ii, int> M; ii cor[1000007]; int skynum[150007]; int component[1000007]; bool engaged[1000007]; vector<int> incomp[1000007]; vector<int> G4[1000007], G8[1000007]; bool vis[1000007]; int ecnt; void add_point(int x, int y) { ii p = {x, y}; if(!M.count(p)) { M[p] = ++cnt; cor[cnt] = p; component[cnt] = cnt; incomp[cnt].push_back(cnt); } } bool check(int i) { bool eng[3][3]; int comp[3][3]; for(int w : G8[i]) { int x = cor[w].X - cor[i].X + 1; int y = cor[w].Y - cor[i].Y + 1; eng[x][y] = engaged[w]; comp[x][y] = component[w]; } if(!eng[0][1] && !eng[1][2] && comp[0][1] == comp[1][2] && eng[0][2] && (eng[0][0] || eng[1][0] || eng[2][0] || eng[2][1] || eng[2][2])) return false; if(!eng[1][2] && !eng[2][1] && comp[1][2] == comp[2][1] && eng[2][2] && (eng[2][0] || eng[1][0] || eng[0][0] || eng[0][1] || eng[0][2])) return false; if(!eng[2][1] && !eng[1][0] && comp[2][1] == comp[1][0] && eng[2][0] && (eng[0][0] || eng[0][1] || eng[0][2] || eng[1][2] || eng[2][2])) return false; if(!eng[1][0] && !eng[0][1] && comp[1][0] == comp[1][0] && eng[0][0] && (eng[0][2] || eng[1][2] || eng[2][2] || eng[2][1] || eng[2][0])) return false; if(!eng[0][1] && !eng[2][1] && comp[0][1] == comp[2][1] && (eng[0][0] || eng[1][0] || eng[2][0]) && (eng[0][2] || eng[1][2] || eng[2][2])) return false; if(!eng[1][0] && !eng[1][2] && comp[1][0] == comp[1][2] && (eng[0][0] || eng[0][1] || eng[0][2]) && (eng[2][0] || eng[2][1] || eng[2][2])) return false; return true; } void merge(int a, int b) { if(a == b) return ; if(incomp[b].size() > incomp[a].size()) swap(a, b); for(int x : incomp[b]) { incomp[a].push_back(x); component[x] = a; } incomp[b].clear(); } void erase(int w) { engaged[w] = 0; for(int u : G4[w]) if(!engaged[u]) merge(component[w], component[u]); } void dfs(int w) { if(vis[w]) return ; vis[w] = 1; ecnt++; for(int u : G8[w]) if(engaged[u]) dfs(u); } int main() { scanf("%d%d", &n, &t); for(int i = 1 ; i <= n ; i++) { int r, c; scanf("%d%d", &r, &c); for(int x = -1 ; x <= 1 ; x++) for(int y = -1 ; y <= 1 ; y++) add_point(r + x, c + y); engaged[M[{r, c}]] = 1; skynum[i] = M[{r, c}]; } for(int i = 1 ; i <= cnt ; i++) { int x = cor[i].X; int y = cor[i].Y; for(int xo = -1 ; xo <= 1 ; xo++) { for(int yo = -1 ; yo <= 1 ; yo++) { ii p2 = {x + xo, y + yo}; if(M.count(p2) == 0) continue; int num = M[p2]; if(xo || yo) G8[i].push_back(num); if((xo || yo) && !(xo && yo)) { G4[i].push_back(num); if(!engaged[i] && !engaged[num]) merge(component[i], component[num]); } } } } dfs(skynum[1]); if(ecnt != n) { printf("NO\n"); return 0; } printf("YES\n"); vector<int> res; for(int i = 0 ; i < n ; i++) { for(int j = n ; j >= 1 ; j--) { if(engaged[skynum[j]] && check(skynum[j])) { erase(skynum[j]); res.push_back(j); break; } } } reverse(res.begin(), res.end()); for(int x : res) printf("%d\n", x); return 0; }

Compilation message (stderr)

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:96:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &t);
  ~~~~~^~~~~~~~~~~~~~~~
skyscrapers.cpp:100:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &r, &c);
   ~~~~~^~~~~~~~~~~~~~~~
#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...