이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |