#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 50;
int n, m, k;
int sx, sy;
string s;
bool bad[N][N];
int p[N*N];
int sz[N*N];
int was[N*N];
int get(int u) {
return (p[u] == u ? u : p[u] = get(p[u]));
}
void unite(int u, int v) {
u = get(u);
v = get(v);
if (u == v)
return;
if (sz[u] > sz[v])
swap(u, v);
p[u] = v;
sz[v] += sz[u];
}
void markBads() {
int x = sx, y = sy;
bad[sx][sy] = true;
for (char c : s) {
if (c == 'N')
x--;
if (c == 'S')
x++;
if (c == 'W')
y--;
if (c == 'E')
y++;
bad[x][y] = true;
}
}
void init(int R, int C, int sr, int sc, int M, char *S) {
n = R;
m = C;
sr--;
sc--;
sx = sr;
sy = sc;
s.clear();
for (int i = 0; i < M; i++)
s += S[i];
markBads();
}
int colour(int ar, int ac, int br, int bc) {
ar--;
ac--;
br--;
bc--;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
p[i*m+j] = i*m+j;
sz[i*m+j] = 1;
}
}
for (int i = ar; i <= br; i++) {
for (int j = ac; j <= bc; j++) {
if (j+1 <= bc && !bad[i][j] && !bad[i][j+1])
unite(i*m+j, i*m+j+1);
if (i+1 <= br && !bad[i][j] && !bad[i+1][j])
unite(i*m+j, (i+1)*m+j);
}
}
int ans = 0;
fill(was, was+n*m, false);
for (int i = ar; i <= br; i++) {
for (int j = ac; j <= bc; j++) {
if (bad[i][j])
continue;
ans += !was[get(i*m+j)];
was[get(i*m+j)] = true;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
17 ms |
376 KB |
Output is correct |
3 |
Correct |
34 ms |
376 KB |
Output is correct |
4 |
Correct |
32 ms |
376 KB |
Output is correct |
5 |
Correct |
16 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
31 ms |
504 KB |
Output is correct |
12 |
Correct |
25 ms |
376 KB |
Output is correct |
13 |
Correct |
18 ms |
376 KB |
Output is correct |
14 |
Correct |
12 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Runtime error |
7 ms |
888 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Runtime error |
7 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
17 ms |
376 KB |
Output is correct |
3 |
Correct |
34 ms |
376 KB |
Output is correct |
4 |
Correct |
32 ms |
376 KB |
Output is correct |
5 |
Correct |
16 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
31 ms |
504 KB |
Output is correct |
12 |
Correct |
25 ms |
376 KB |
Output is correct |
13 |
Correct |
18 ms |
376 KB |
Output is correct |
14 |
Correct |
12 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Runtime error |
7 ms |
1144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
17 ms |
376 KB |
Output is correct |
3 |
Correct |
34 ms |
376 KB |
Output is correct |
4 |
Correct |
32 ms |
376 KB |
Output is correct |
5 |
Correct |
16 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
31 ms |
504 KB |
Output is correct |
12 |
Correct |
25 ms |
376 KB |
Output is correct |
13 |
Correct |
18 ms |
376 KB |
Output is correct |
14 |
Correct |
12 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Runtime error |
7 ms |
1144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |