// brutao mais burro possivel
#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
constexpr int maxn = 55*55, lado = 55;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
struct DSU {
int pai[maxn], peso[maxn];
void init() { for(int i = 0; i < maxn; i++) pai[i] = i, peso[i] = 1; }
int find(int x) { return pai[x] == x ? x : pai[x] = find(pai[x]); }
void join(int a, int b) {
a = find(a), b = find(b);
if(a == b) return;
if(peso[a] < peso[b])
swap(a, b);
pai[b] = a;
peso[a] += peso[b];
}
} dsu;
bool mark[lado][lado];
void dfs(int x, int y, int here, int moves, char *S) {
mark[x][y] = 1;
if(here == moves) return;
char c = S[here];
if(c == 'N') dfs(x-1, y, here+1, moves, S);
else if(c == 'S') dfs(x+1, y, here+1, moves, S);
else if(c == 'W') dfs(x, y-1, here+1, moves, S);
else if(c == 'E') dfs(x, y+1, here+1, moves, S);
}
void init(int R, int C, int sr, int sc, int M, char *S) {
if(max(R, C) > 50) assert(0);
dfs(sr, sc, 0, M, S);
}
int get(int a, int b) { return a * (51) + b; }
int colour(int ar, int ac, int br, int bc) {
dsu.init();
for(int r = ar; r <= br; r++) {
for(int c = ac; c <= bc; c++) {
if(mark[r][c]) continue;
for(int k = 0; k < 4; k++)
if(!mark[r+dx[k]][c+dy[k]])
dsu.join(get(r,c), get(r + dx[k], c + dy[k]));
}
}
vector<int> siuu;
for(int r = ar; r <= br; r++)
for(int c = ac; c <= bc; c++)
if(!mark[r][c])
siuu.push_back(dsu.find(get(r, c)));
sort(siuu.begin(), siuu.end());
return unique(siuu.begin(), siuu.end()) - siuu.begin();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
14 ms |
380 KB |
Output is correct |
3 |
Incorrect |
36 ms |
388 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Runtime error |
1 ms |
700 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Runtime error |
1 ms |
724 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
14 ms |
380 KB |
Output is correct |
3 |
Incorrect |
36 ms |
388 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
14 ms |
380 KB |
Output is correct |
3 |
Incorrect |
36 ms |
388 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |