#include "rainbow.h"
#include <queue>
using namespace std;
const int N = 200005;
int color[3][N];
int st[N];
int st1[N];
int st2[N];
int calooooor[55][55];
int sttttttt[55][55];
int ent = 0;
void init(int R, int C, int sr, int sc, int M, char *S) {
if (R == 2)
ent = 1;
if (ent == 1)
{
color[sr][sc] = 1;
for (int i = 0; i < M; i++)
{
if (S[i] == 'W')
{
sc--;
}
if (S[i] == 'S')
{
sr++;
}
if (S[i] == 'E')
{
sc++;
}
if (S[i] == 'N')
{
sr--;
}
color[sr][sc] = 1;
}
if (color[1][1] == 0 || color[2][1] == 0)
st[1] = 1;
for (int i = 2; i <= C; i++)
{
if ((color[1][i] == 0 && color[1][i - 1] == 0) || (color[2][i] == 0 && color[2][i - 1] == 0))
st[i] = st[i - 1];
else
{
if (color[1][i] == 0 || color[2][i] == 0)
st[i] = st[i + 1];
else
st[i] = st[i - 1];
}
}
if (color[1][1] == 0)
st1[1] = 1;
for (int i = 2; i <= C; i++)
{
if (color[1][i] == 1)
st1[i] = st1[i - 1];
else if (color[1][i - 1] == 0)
st1[i] = st1[i - 1];
else
st1[i] = st1[i - 1] + 1;
}
if (color[2][1] == 0)
st2[1] = 1;
for (int i = 2; i <= C; i++)
{
if (color[2][i] == 1)
st2[i] = st2[i - 1];
else if (color[2][i - 1] == 0)
st2[i] = st2[i - 1];
else
st2[i] = st2[i - 1] + 1;
}
}
else
{
calooooor[sr][sc] = 1;
for (int i = 0; i < M; i++)
{
if (S[i] == 'W')
{
sc--;
}
if (S[i] == 'S')
{
sr++;
}
if (S[i] == 'E')
{
sc++;
}
if (S[i] == 'N')
{
sr--;
}
calooooor[sr][sc] = 1;
}
}
}
int colour(int ar, int ac, int br, int bc) {
if (ent == 1)
{
int qan = 0;
if (ar == 1 && br == 1)
{
if (color[1][ac] == color[1][ac - 1] && color[1][ac] == 0)
{
qan = st1[bc] - st1[ac - 1] + 1;
}
else
{
qan = st1[bc] - st1[ac - 1];
}
}
else if (ar == 2 && br == 2)
{
if (color[2][ac] == color[2][ac - 1] && color[2][ac] == 0)
{
qan = st2[bc] - st2[ac - 1] + 1;
}
else
{
qan = st2[bc] - st2[ac - 1];
}
}
else
{
if ((color[1][ac] == 0 && color[1][ac - 1] == 0) || (color[2][ac] == 0 && color[2][ac - 1] == 0))
{
qan = st2[bc] - st2[ac - 1] + 1;
}
else
{
qan = st2[bc] - st2[ac - 1];
}
}
return qan;
}
else
{
queue<pair<int, int>> q;
for (int i = ar; i <= br; i++)
{
for (int j = ac; j <= bc; j++)
{
sttttttt[i][j] = 0;
}
}
int qan = 0;
for (int i = ar; i <= br; i++)
{
for (int j = ac; j <= bc; j++)
{
if (sttttttt[i][j] == 0 && calooooor[i][j] == 0)
{
qan++;
int qq = 0;
q.push({ i, j });
sttttttt[i][j] = 1;
while (!q.empty())
{
qq++;
int x = q.front().first, y = q.front().second;
q.pop();
sttttttt[x][y] = 1;
if (x + 1 <= br && calooooor[x + 1][y] == 0 && sttttttt[x + 1][y] == 0)
{
q.push({ x + 1, y });
sttttttt[x + 1][y] = 1;
}
if (x - 1 >= ar && calooooor[x - 1][y] == 0 && sttttttt[x - 1][y] == 0)
{
q.push({ x - 1, y });
sttttttt[x - 1][y] = 1;
}
if (y + 1 <= bc && calooooor[x][y + 1] == 0 && sttttttt[x][y + 1] == 0)
{
q.push({ x, y + 1 });
sttttttt[x][y + 1] = 1;
}
if (y - 1 >= ac && calooooor[x][y - 1] == 0 && sttttttt[x][y - 1] == 0)
{
q.push({ x, y - 1 });
sttttttt[x][y - 1] = 1;
}
}
}
}
}
for (int i = ar; i <= br; i++)
{
for (int j = ac; j <= bc; j++)
{
sttttttt[i][j] = 0;
}
}
return qan;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
11 ms |
212 KB |
Output is correct |
4 |
Correct |
11 ms |
320 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
10 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
320 KB |
Output is correct |
14 |
Correct |
4 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
11 ms |
212 KB |
Output is correct |
4 |
Correct |
11 ms |
320 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
10 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
320 KB |
Output is correct |
14 |
Correct |
4 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
11 ms |
212 KB |
Output is correct |
4 |
Correct |
11 ms |
320 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
10 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
320 KB |
Output is correct |
14 |
Correct |
4 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |