# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
408612 | syl123456 | Land of the Rainbow Gold (APIO17_rainbow) | C++17 | 3058 ms | 1048580 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<bool>> b;
vector<int> p;
int m;
void init(int R, int C, int sr, int sc, int M, char *S) {
m = C;
b.assign(R, vector<bool>(C, false));
p.resize(R * C);
--sr, --sc;
b[sr][sc] = true;
for (int i = 0; i < M; ++i) {
if (S[i] == 'N') --sr;
else if (S[i] == 'S') ++sr;
else if (S[i] == 'W') --sc;
else ++sc;
b[sr][sc] = true;
}
}
int colour(int ar, int ac, int br, int bc) {
--ar, --ac;
int _ = 0;
for (int i = ar; i < br; ++i) for (int j = ac; j < bc; ++j)
p[i * m + j] = i * m + j;
function<int(int)> find = [&](int i) {
return p[i] = p[i] == i ? i : find(p[i]);
};
for (int i = ar; i < br; ++i) for (int j = ac; j < bc; ++j) if (!b[i][j]) {
if (i < br - 1 && !b[i + 1][j])
p[find(i * m + j)] = find((i + 1) * m + j);
if (j < bc - 1 && !b[i][j + 1])
p[find(i * m + j)] = find(i * m + j + 1);
}
int ans = 0;
for (int i = ar; i < br; ++i) for (int j = ac; j < bc; ++j) if (!b[i][j])
ans += find(i * m + j) == i * m + j;
return ans;
}
Compilation message (stderr)
# | 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... |