#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
rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:24:9: warning: unused variable '_' [-Wunused-variable]
24 | int _ = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
204 KB |
Output is correct |
2 |
Correct |
25 ms |
312 KB |
Output is correct |
3 |
Correct |
96 ms |
292 KB |
Output is correct |
4 |
Correct |
98 ms |
292 KB |
Output is correct |
5 |
Correct |
23 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
70 ms |
416 KB |
Output is correct |
12 |
Correct |
54 ms |
204 KB |
Output is correct |
13 |
Correct |
22 ms |
312 KB |
Output is correct |
14 |
Correct |
9 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
3058 ms |
10728 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
433 ms |
1048580 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
204 KB |
Output is correct |
2 |
Correct |
25 ms |
312 KB |
Output is correct |
3 |
Correct |
96 ms |
292 KB |
Output is correct |
4 |
Correct |
98 ms |
292 KB |
Output is correct |
5 |
Correct |
23 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
70 ms |
416 KB |
Output is correct |
12 |
Correct |
54 ms |
204 KB |
Output is correct |
13 |
Correct |
22 ms |
312 KB |
Output is correct |
14 |
Correct |
9 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Execution timed out |
3045 ms |
4496 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
204 KB |
Output is correct |
2 |
Correct |
25 ms |
312 KB |
Output is correct |
3 |
Correct |
96 ms |
292 KB |
Output is correct |
4 |
Correct |
98 ms |
292 KB |
Output is correct |
5 |
Correct |
23 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
70 ms |
416 KB |
Output is correct |
12 |
Correct |
54 ms |
204 KB |
Output is correct |
13 |
Correct |
22 ms |
312 KB |
Output is correct |
14 |
Correct |
9 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Execution timed out |
3045 ms |
4496 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |