#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,C = 0;
for(auto [r,c]:pts){
if(r >= ar && r <= br && c >= ac && c <= bc){
k[{r,c}] = 1;
}
}
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})){
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;
// cout << V << ' ' << C << ' ' << E << '\n';
return C - V + E - bf;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
344 KB |
Output is correct |
2 |
Correct |
130 ms |
600 KB |
Output is correct |
3 |
Correct |
84 ms |
348 KB |
Output is correct |
4 |
Correct |
99 ms |
348 KB |
Output is correct |
5 |
Correct |
206 ms |
652 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 |
158 ms |
348 KB |
Output is correct |
12 |
Correct |
310 ms |
592 KB |
Output is correct |
13 |
Correct |
300 ms |
612 KB |
Output is correct |
14 |
Correct |
580 ms |
752 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 |
3037 ms |
53328 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
535 ms |
45388 KB |
Output is correct |
3 |
Correct |
515 ms |
44896 KB |
Output is correct |
4 |
Correct |
441 ms |
38752 KB |
Output is correct |
5 |
Correct |
206 ms |
21184 KB |
Output is correct |
6 |
Correct |
893 ms |
63092 KB |
Output is correct |
7 |
Correct |
1334 ms |
90520 KB |
Output is correct |
8 |
Correct |
47 ms |
5832 KB |
Output is correct |
9 |
Correct |
27 ms |
3528 KB |
Output is correct |
10 |
Correct |
14 ms |
2004 KB |
Output is correct |
11 |
Correct |
63 ms |
6768 KB |
Output is correct |
12 |
Correct |
154 ms |
15048 KB |
Output is correct |
13 |
Correct |
163 ms |
15048 KB |
Output is correct |
14 |
Correct |
169 ms |
15044 KB |
Output is correct |
15 |
Correct |
164 ms |
14788 KB |
Output is correct |
16 |
Correct |
674 ms |
50956 KB |
Output is correct |
17 |
Correct |
622 ms |
46532 KB |
Output is correct |
18 |
Correct |
906 ms |
62924 KB |
Output is correct |
19 |
Correct |
889 ms |
63432 KB |
Output is correct |
20 |
Correct |
626 ms |
51400 KB |
Output is correct |
21 |
Correct |
258 ms |
22592 KB |
Output is correct |
22 |
Correct |
197 ms |
18888 KB |
Output is correct |
23 |
Correct |
333 ms |
29352 KB |
Output is correct |
24 |
Correct |
471 ms |
39880 KB |
Output is correct |
25 |
Correct |
1566 ms |
114120 KB |
Output is correct |
26 |
Correct |
1582 ms |
114092 KB |
Output is correct |
27 |
Correct |
1626 ms |
114116 KB |
Output is correct |
28 |
Correct |
1526 ms |
110792 KB |
Output is correct |
29 |
Correct |
1476 ms |
103904 KB |
Output is correct |
30 |
Correct |
1647 ms |
107976 KB |
Output is correct |
31 |
Correct |
1625 ms |
114116 KB |
Output is correct |
32 |
Correct |
1728 ms |
114068 KB |
Output is correct |
33 |
Correct |
1634 ms |
114128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
344 KB |
Output is correct |
2 |
Correct |
130 ms |
600 KB |
Output is correct |
3 |
Correct |
84 ms |
348 KB |
Output is correct |
4 |
Correct |
99 ms |
348 KB |
Output is correct |
5 |
Correct |
206 ms |
652 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 |
158 ms |
348 KB |
Output is correct |
12 |
Correct |
310 ms |
592 KB |
Output is correct |
13 |
Correct |
300 ms |
612 KB |
Output is correct |
14 |
Correct |
580 ms |
752 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 |
3047 ms |
6304 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
344 KB |
Output is correct |
2 |
Correct |
130 ms |
600 KB |
Output is correct |
3 |
Correct |
84 ms |
348 KB |
Output is correct |
4 |
Correct |
99 ms |
348 KB |
Output is correct |
5 |
Correct |
206 ms |
652 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 |
158 ms |
348 KB |
Output is correct |
12 |
Correct |
310 ms |
592 KB |
Output is correct |
13 |
Correct |
300 ms |
612 KB |
Output is correct |
14 |
Correct |
580 ms |
752 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 |
3047 ms |
6304 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |