#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
vector<vector<bool>> land;
void init(int R, int C, int sr, int sc, int M, char *S){
sr--;
sc--;
land = vector<vector<bool>>(R, vector<bool>(C, true));
int x = sr, y = sc;
land[x][y] = false;
for (int i = 0; i < M; i++){
if (S[i] == 'N'){
x--;
}
if (S[i] == 'S'){
x++;
}
if (S[i] == 'E'){
y++;
}
if (S[i] == 'W'){
y--;
}
land[x][y] = false;
}
}
int colour(int ar, int ac, int br, int bc){
ar--;
ac--;
int R = land.size();
int C = land[0].size();
vector<vector<bool>> used(R, vector<bool>(C, false));
int ans = 0;
for (int i = ar; i < br; i++){
for (int j = ac; j < bc; j++){
if (land[i][j] && !used[i][j]){
ans++;
used[i][j] = true;
queue<pair<int, int>> Q;
Q.push(make_pair(i, j));
while (!Q.empty()){
int x = Q.front().first;
int y = Q.front().second;
Q.pop();
for (int k = 0; k < 4; k++){
int x2 = x + dx[k];
int y2 = y + dy[k];
if (ar <= x2 && x2 < br && ac <= y2 && y2 < bc){
if (land[x2][y2] && !used[x2][y2]){
used[x2][y2] = true;
Q.push(make_pair(x2, y2));
}
}
}
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
19 ms |
352 KB |
Output is correct |
3 |
Correct |
31 ms |
340 KB |
Output is correct |
4 |
Correct |
33 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
36 ms |
348 KB |
Output is correct |
12 |
Correct |
25 ms |
348 KB |
Output is correct |
13 |
Correct |
21 ms |
340 KB |
Output is correct |
14 |
Correct |
23 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
3076 ms |
724 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
467 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
19 ms |
352 KB |
Output is correct |
3 |
Correct |
31 ms |
340 KB |
Output is correct |
4 |
Correct |
33 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
36 ms |
348 KB |
Output is correct |
12 |
Correct |
25 ms |
348 KB |
Output is correct |
13 |
Correct |
21 ms |
340 KB |
Output is correct |
14 |
Correct |
23 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Execution timed out |
3063 ms |
736 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
19 ms |
352 KB |
Output is correct |
3 |
Correct |
31 ms |
340 KB |
Output is correct |
4 |
Correct |
33 ms |
348 KB |
Output is correct |
5 |
Correct |
18 ms |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
36 ms |
348 KB |
Output is correct |
12 |
Correct |
25 ms |
348 KB |
Output is correct |
13 |
Correct |
21 ms |
340 KB |
Output is correct |
14 |
Correct |
23 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Execution timed out |
3063 ms |
736 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |