# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
247532 | 2020-07-11T14:57:36 Z | mieszko11b | Building Skyscrapers (CEOI19_skyscrapers) | C++14 | 3500 ms | 156792 KB |
#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(!engaged[i] && !engaged[num]) merge(component[i], component[num]); } if((xo || yo) && !(xo && yo)) G4[i].push_back(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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 70776 KB | ans=YES N=1 |
2 | Correct | 45 ms | 70776 KB | ans=YES N=4 |
3 | Correct | 43 ms | 70784 KB | ans=NO N=4 |
4 | Correct | 47 ms | 70776 KB | ans=YES N=5 |
5 | Correct | 45 ms | 70776 KB | ans=YES N=9 |
6 | Correct | 45 ms | 70780 KB | ans=YES N=5 |
7 | Correct | 44 ms | 70784 KB | ans=NO N=9 |
8 | Correct | 45 ms | 70776 KB | ans=NO N=10 |
9 | Incorrect | 43 ms | 70776 KB | Full cells must be connected |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 70776 KB | ans=YES N=1 |
2 | Correct | 45 ms | 70776 KB | ans=YES N=4 |
3 | Correct | 43 ms | 70784 KB | ans=NO N=4 |
4 | Correct | 47 ms | 70776 KB | ans=YES N=5 |
5 | Correct | 45 ms | 70776 KB | ans=YES N=9 |
6 | Correct | 45 ms | 70780 KB | ans=YES N=5 |
7 | Correct | 44 ms | 70784 KB | ans=NO N=9 |
8 | Correct | 45 ms | 70776 KB | ans=NO N=10 |
9 | Incorrect | 43 ms | 70776 KB | Full cells must be connected |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 70776 KB | ans=YES N=1 |
2 | Correct | 45 ms | 70776 KB | ans=YES N=4 |
3 | Correct | 43 ms | 70784 KB | ans=NO N=4 |
4 | Correct | 47 ms | 70776 KB | ans=YES N=5 |
5 | Correct | 45 ms | 70776 KB | ans=YES N=9 |
6 | Correct | 45 ms | 70780 KB | ans=YES N=5 |
7 | Correct | 44 ms | 70784 KB | ans=NO N=9 |
8 | Correct | 45 ms | 70776 KB | ans=NO N=10 |
9 | Incorrect | 43 ms | 70776 KB | Full cells must be connected |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 89 ms | 73976 KB | ans=NO N=1934 |
2 | Correct | 63 ms | 71928 KB | ans=NO N=1965 |
3 | Incorrect | 68 ms | 71288 KB | Full cells must be connected |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 70776 KB | ans=YES N=1 |
2 | Correct | 45 ms | 70776 KB | ans=YES N=4 |
3 | Correct | 43 ms | 70784 KB | ans=NO N=4 |
4 | Correct | 47 ms | 70776 KB | ans=YES N=5 |
5 | Correct | 45 ms | 70776 KB | ans=YES N=9 |
6 | Correct | 45 ms | 70780 KB | ans=YES N=5 |
7 | Correct | 44 ms | 70784 KB | ans=NO N=9 |
8 | Correct | 45 ms | 70776 KB | ans=NO N=10 |
9 | Incorrect | 43 ms | 70776 KB | Full cells must be connected |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 574 ms | 93148 KB | ans=NO N=66151 |
2 | Correct | 1648 ms | 156792 KB | ans=NO N=64333 |
3 | Execution timed out | 3559 ms | 87800 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 89 ms | 73976 KB | ans=NO N=1934 |
2 | Correct | 63 ms | 71928 KB | ans=NO N=1965 |
3 | Incorrect | 68 ms | 71288 KB | Full cells must be connected |
4 | Halted | 0 ms | 0 KB | - |