#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
#define eb emplace_back
vector<ii> cells, nodes, horiz, vert;
void init(int R, int C, int sr, int sc, int M, char *S) {
cells.eb(sr, sc);
for (int i = 0; i < M; i++) {
if (S[i] == 'N') {
sr--;
} else if (S[i] == 'S') {
sr++;
} else if (S[i] == 'E') {
sc++;
} else {
sc--;
}
cells.eb(sr, sc);
}
sort(cells.begin(), cells.end());
cells.erase(unique(cells.begin(), cells.end()), cells.end());
for (const auto &[r, c] : cells) {
nodes.eb(r, c);
nodes.eb(r + 1, c);
nodes.eb(r, c + 1);
nodes.eb(r + 1, c + 1);
horiz.eb(r, c);
horiz.eb(r + 1, c);
vert.eb(r, c);
vert.eb(r, c + 1);
}
for (auto *vec : {&nodes, &horiz, &vert}) {
sort(vec->begin(), vec->end());
vec->erase(unique(vec->begin(), vec->end()), vec->end());
}
}
int colour(int ar, int ac, int br, int bc) {
int V = (br - ar + 1) * 2 + (bc - ac + 1) * 2 - 4, E = V;
bool border = 0;
for (const auto &[r, c] : nodes) {
if (ar + 1 <= r && r <= br && ac + 1 <= c && c <= bc) {
V++;
} else if (((ar == r || br + 1 == r) && (ac <= c && c <= bc + 1)) || ((ac == c || bc + 1 == c) && (ar <= r && r <= br + 1))) {
border = 1;
}
}
if (!border) {
bool wraps = 0;
for (const auto &[r, c] : cells) {
if (ar <= r && r <= br && ac <= c && c <= bc) {
wraps = 1;
}
}
if (!wraps) {
return 1;
}
V = nodes.size();
E = horiz.size() + vert.size();
int F = 2 - (V - E), water_F = cells.size();
return F - water_F;
}
for (const auto &[r, c] : horiz) {
if (ar + 1 <= r && r <= br && ac <= c && c <= bc) {
E++;
}
}
for (const auto &[r, c] : vert) {
if (ar <= r && r <= br && ac + 1 <= c && c <= bc) {
E++;
}
}
int F = 2 - (V - E), water_F = 0;
for (const auto &[r, c] : cells) {
if (ar <= r && r <= br && ac <= c && c <= bc) {
water_F++;
}
}
return F - water_F - 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
644 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
604 KB |
Output is correct |
14 |
Correct |
11 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
3057 ms |
6244 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
38 ms |
11208 KB |
Output is correct |
3 |
Correct |
19 ms |
10696 KB |
Output is correct |
4 |
Correct |
20 ms |
12300 KB |
Output is correct |
5 |
Correct |
22 ms |
9412 KB |
Output is correct |
6 |
Correct |
14 ms |
4044 KB |
Output is correct |
7 |
Correct |
22 ms |
5580 KB |
Output is correct |
8 |
Correct |
36 ms |
9928 KB |
Output is correct |
9 |
Correct |
37 ms |
10900 KB |
Output is correct |
10 |
Correct |
11 ms |
3024 KB |
Output is correct |
11 |
Correct |
23 ms |
5576 KB |
Output is correct |
12 |
Correct |
43 ms |
10776 KB |
Output is correct |
13 |
Correct |
19 ms |
10696 KB |
Output is correct |
14 |
Correct |
21 ms |
11388 KB |
Output is correct |
15 |
Correct |
21 ms |
10692 KB |
Output is correct |
16 |
Correct |
13 ms |
3792 KB |
Output is correct |
17 |
Correct |
21 ms |
5784 KB |
Output is correct |
18 |
Correct |
34 ms |
10696 KB |
Output is correct |
19 |
Correct |
28 ms |
11720 KB |
Output is correct |
20 |
Correct |
28 ms |
10696 KB |
Output is correct |
21 |
Correct |
36 ms |
10656 KB |
Output is correct |
22 |
Correct |
36 ms |
9708 KB |
Output is correct |
23 |
Correct |
11 ms |
3024 KB |
Output is correct |
24 |
Correct |
22 ms |
5776 KB |
Output is correct |
25 |
Correct |
38 ms |
11208 KB |
Output is correct |
26 |
Correct |
19 ms |
10696 KB |
Output is correct |
27 |
Correct |
20 ms |
11200 KB |
Output is correct |
28 |
Correct |
20 ms |
9156 KB |
Output is correct |
29 |
Correct |
14 ms |
3792 KB |
Output is correct |
30 |
Correct |
22 ms |
5672 KB |
Output is correct |
31 |
Correct |
35 ms |
11720 KB |
Output is correct |
32 |
Correct |
28 ms |
11204 KB |
Output is correct |
33 |
Correct |
28 ms |
10780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
644 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
604 KB |
Output is correct |
14 |
Correct |
11 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Execution timed out |
3072 ms |
6312 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
644 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
604 KB |
Output is correct |
14 |
Correct |
11 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Execution timed out |
3072 ms |
6312 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |