제출 #974051

#제출 시각아이디문제언어결과실행 시간메모리
974051colossal_pepe무지개나라 (APIO17_rainbow)C++17
11 / 100
10 ms504 KiB
#include "rainbow.h" #include <bits/stdc++.h> using namespace std; struct DSU { vector<int> e; DSU(int sz) { e.resize(sz, -1); } int find(int x) { return (e[x] < 0 ? x : e[x] = find(e[x])); } bool merge(int x, int y) { x = find(x), y = find(y); if (x == y) return 0; if (-e[x] < -e[y]) swap(x, y); e[x] += e[y], e[y] = x; return 1; } }; vector<vector<bool>> g; void init(int R, int C, int sr, int sc, int M, char *S) { if (R > 50 or C > 50) exit(0); g.resize(R, vector<bool>(C, 1)); g[--sr][--sc] = 0; for (int i = 0; i < M; i++) { if (S[i] == 'N') sr--; if (S[i] == 'S') sr++; if (S[i] == 'E') sc++; if (S[i] == 'W') sc--; g[sr][sc] = 0; } } int colour(int ar, int ac, int br, int bc) { ar--, ac--, br--, bc--; auto id = [ar, ac, br, bc](int i, int j) { return (i - ar) * (bc - ac + 1) + j - ac; }; int comps = (br - ar + 1) * (bc - ac + 1); DSU dsu = DSU(comps); for (int i = ar; i <= br; i++) { for (int j = ac; j <= bc; j++) { if (not g[i][j]) { comps--; continue; } if (j + 1 <= bc and g[i][j + 1]) comps -= dsu.merge(id(i, j), id(i, j + 1)); if (i + 1 <= br and g[i + 1][j]) comps -= dsu.merge(id(i, j), id(i + 1, j)); } } return comps; }
#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...