#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
vector<pair<int,int>> pts;
void init(int R, int C, int sr, int sc, int M, char *S) {
pts.push_back({sr,sc});
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++;
}
assert(sr <= R && sr >= 1);
assert(sc <= C && sc >= 1);
pts.push_back({sr,sc});
}
sort(pts.begin(),pts.end());
pts.resize(unique(pts.begin(),pts.end()) - pts.begin());
}
map<pair<int,int>,bool> k,vis;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
int colour(int ar, int ac, int br, int bc) {
// V - E + F = 1 + C -> F = 1 + C - V + E
k.clear();
vis.clear();
int V = 0,E = 0;
bool ok =true;
for(auto [r,c]:pts){
if(r >= ar && r <= br && c >= ac && c <= bc){
k[{r,c}] = 1;
if(r == ar || r == br || c == ac || c == bc){
ok=false;
}
}
}
if(k.empty()){
ok=false;
}
for(int i = ar - 1;i <= br + 1;i++){
k[{i,ac-1}] = k[{i,bc+1}] = 1;
}
for(int i = ac - 1;i <= bc + 1;i++){
k[{ar-1,i}] = k[{br+1,i}] = 1;
}
int bf = 0;
for(auto [xx,_y]:k){
auto [r,c] = xx;
if(k.count({r + 1,c}) && k.count({r,c + 1}) && k.count({r + 1,c + 1})){
bf++;
}
if(k.count({r+1,c+1}) && !k.count({r+1,c}) && !k.count({r,c+1})){
E += 2;
}
if(k.count({r+1,c-1}) && !k.count({r+1,c}) && !k.count({r,c-1})){
E += 2;
}
if(!vis.count({r,c})){
queue<pair<int,int>> q;
q.push({r,c});
vis[{r,c}]=1;
while(!q.empty()){
V++;
auto [x,y] = q.front();q.pop();
// cout << x << ' ' << y << '\n';
for(int i = 0;i < 4;i++){
int _x = x + dx[i],_y = y + dy[i];
if(k.count({_x,_y})){
E++;
}
if(k.count({_x,_y}) && !vis.count({_x,_y})){
vis[{_x,_y}]=1;
q.push({_x,_y});
}
}
}
}
}
assert(E%2==0);
E /= 2;
return -V + E - bf + 1+ok;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
348 KB |
Output is correct |
2 |
Correct |
124 ms |
344 KB |
Output is correct |
3 |
Correct |
88 ms |
344 KB |
Output is correct |
4 |
Correct |
100 ms |
512 KB |
Output is correct |
5 |
Correct |
196 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
344 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 |
157 ms |
536 KB |
Output is correct |
12 |
Correct |
293 ms |
596 KB |
Output is correct |
13 |
Correct |
314 ms |
624 KB |
Output is correct |
14 |
Correct |
530 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
3029 ms |
53452 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
532 ms |
45248 KB |
Output is correct |
3 |
Correct |
531 ms |
45000 KB |
Output is correct |
4 |
Correct |
474 ms |
38808 KB |
Output is correct |
5 |
Correct |
209 ms |
21440 KB |
Output is correct |
6 |
Correct |
796 ms |
63092 KB |
Output is correct |
7 |
Correct |
1277 ms |
90620 KB |
Output is correct |
8 |
Correct |
48 ms |
5828 KB |
Output is correct |
9 |
Correct |
27 ms |
3528 KB |
Output is correct |
10 |
Correct |
14 ms |
2004 KB |
Output is correct |
11 |
Correct |
62 ms |
6744 KB |
Output is correct |
12 |
Correct |
155 ms |
15120 KB |
Output is correct |
13 |
Correct |
156 ms |
15300 KB |
Output is correct |
14 |
Correct |
164 ms |
15044 KB |
Output is correct |
15 |
Correct |
157 ms |
14888 KB |
Output is correct |
16 |
Correct |
686 ms |
51140 KB |
Output is correct |
17 |
Correct |
618 ms |
46788 KB |
Output is correct |
18 |
Correct |
851 ms |
62836 KB |
Output is correct |
19 |
Correct |
848 ms |
63432 KB |
Output is correct |
20 |
Correct |
626 ms |
51392 KB |
Output is correct |
21 |
Correct |
269 ms |
22464 KB |
Output is correct |
22 |
Correct |
202 ms |
18752 KB |
Output is correct |
23 |
Correct |
375 ms |
29480 KB |
Output is correct |
24 |
Correct |
479 ms |
39880 KB |
Output is correct |
25 |
Correct |
1590 ms |
114112 KB |
Output is correct |
26 |
Correct |
1554 ms |
114156 KB |
Output is correct |
27 |
Correct |
1494 ms |
113920 KB |
Output is correct |
28 |
Correct |
1448 ms |
110788 KB |
Output is correct |
29 |
Correct |
1427 ms |
103964 KB |
Output is correct |
30 |
Correct |
1561 ms |
107720 KB |
Output is correct |
31 |
Correct |
1540 ms |
114008 KB |
Output is correct |
32 |
Correct |
1587 ms |
114124 KB |
Output is correct |
33 |
Correct |
1574 ms |
113912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
348 KB |
Output is correct |
2 |
Correct |
124 ms |
344 KB |
Output is correct |
3 |
Correct |
88 ms |
344 KB |
Output is correct |
4 |
Correct |
100 ms |
512 KB |
Output is correct |
5 |
Correct |
196 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
344 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 |
157 ms |
536 KB |
Output is correct |
12 |
Correct |
293 ms |
596 KB |
Output is correct |
13 |
Correct |
314 ms |
624 KB |
Output is correct |
14 |
Correct |
530 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 |
3050 ms |
6220 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
348 KB |
Output is correct |
2 |
Correct |
124 ms |
344 KB |
Output is correct |
3 |
Correct |
88 ms |
344 KB |
Output is correct |
4 |
Correct |
100 ms |
512 KB |
Output is correct |
5 |
Correct |
196 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
344 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 |
157 ms |
536 KB |
Output is correct |
12 |
Correct |
293 ms |
596 KB |
Output is correct |
13 |
Correct |
314 ms |
624 KB |
Output is correct |
14 |
Correct |
530 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 |
3050 ms |
6220 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |