#include "rainbow.h"
#include <set>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
int const N=2e5+10;
set<int>riv[N]={};
int r,c;
void init(int R, int C, int sr, int sc, int M, char *S)
{
riv[sr].insert(sc);
for (int i=0;i<M;i++)
{
if (S[i]=='N')
sr--;
if (S[i]=='S')
sr++;
if (S[i]=='W')
sc--;
if (S[i]=='E')
sc++;
riv[sr].insert(sc);
}
r=R;
c=C;
}
vector<int>di[2]={{-1,1,0,0},{0,0,-1,1}};
int colour(int ar, int ac, int br, int bc)
{
if (r<=1000&&c<=1000)
{
int ans=0;
bool vis[r+10][c+10]={};
for (int i=ar;i<=br;i++)
{
for (int j=ac;j<=bc;j++)
{
if (!vis[i][j]&&riv[i].find(j)==riv[i].end())
{
ans++;
vis[i][j]=1;
queue<pair<int,int>>Q;
Q.push({i,j});
while (Q.size())
{
int i,j;
tie(i,j)=Q.front();
Q.pop();
for (int k=0;k<4;k++)
{
int x=i+di[0][k],y=j+di[1][k];
if (x>=ar&&x<=br&&y>=ac&&y<=bc&&!vis[x][y]&&riv[x].find(y)==riv[x].end())
{
vis[x][y]=1;
Q.push({x,y});
}
}
}
}
}
}
return ans;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9816 KB |
Output is correct |
2 |
Correct |
13 ms |
9816 KB |
Output is correct |
3 |
Correct |
17 ms |
9820 KB |
Output is correct |
4 |
Correct |
18 ms |
9820 KB |
Output is correct |
5 |
Correct |
14 ms |
9908 KB |
Output is correct |
6 |
Correct |
2 ms |
9820 KB |
Output is correct |
7 |
Correct |
2 ms |
9820 KB |
Output is correct |
8 |
Correct |
2 ms |
9816 KB |
Output is correct |
9 |
Correct |
2 ms |
9820 KB |
Output is correct |
10 |
Correct |
2 ms |
9820 KB |
Output is correct |
11 |
Correct |
21 ms |
9816 KB |
Output is correct |
12 |
Correct |
19 ms |
9816 KB |
Output is correct |
13 |
Correct |
29 ms |
9820 KB |
Output is correct |
14 |
Correct |
22 ms |
9816 KB |
Output is correct |
15 |
Correct |
2 ms |
9564 KB |
Output is correct |
16 |
Correct |
2 ms |
9820 KB |
Output is correct |
17 |
Correct |
2 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9820 KB |
Output is correct |
2 |
Correct |
2 ms |
9820 KB |
Output is correct |
3 |
Incorrect |
48 ms |
15796 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9564 KB |
Output is correct |
2 |
Incorrect |
18 ms |
14428 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9816 KB |
Output is correct |
2 |
Correct |
13 ms |
9816 KB |
Output is correct |
3 |
Correct |
17 ms |
9820 KB |
Output is correct |
4 |
Correct |
18 ms |
9820 KB |
Output is correct |
5 |
Correct |
14 ms |
9908 KB |
Output is correct |
6 |
Correct |
2 ms |
9820 KB |
Output is correct |
7 |
Correct |
2 ms |
9820 KB |
Output is correct |
8 |
Correct |
2 ms |
9816 KB |
Output is correct |
9 |
Correct |
2 ms |
9820 KB |
Output is correct |
10 |
Correct |
2 ms |
9820 KB |
Output is correct |
11 |
Correct |
21 ms |
9816 KB |
Output is correct |
12 |
Correct |
19 ms |
9816 KB |
Output is correct |
13 |
Correct |
29 ms |
9820 KB |
Output is correct |
14 |
Correct |
22 ms |
9816 KB |
Output is correct |
15 |
Correct |
2 ms |
9564 KB |
Output is correct |
16 |
Correct |
2 ms |
9820 KB |
Output is correct |
17 |
Correct |
2 ms |
9820 KB |
Output is correct |
18 |
Execution timed out |
3073 ms |
13520 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9816 KB |
Output is correct |
2 |
Correct |
13 ms |
9816 KB |
Output is correct |
3 |
Correct |
17 ms |
9820 KB |
Output is correct |
4 |
Correct |
18 ms |
9820 KB |
Output is correct |
5 |
Correct |
14 ms |
9908 KB |
Output is correct |
6 |
Correct |
2 ms |
9820 KB |
Output is correct |
7 |
Correct |
2 ms |
9820 KB |
Output is correct |
8 |
Correct |
2 ms |
9816 KB |
Output is correct |
9 |
Correct |
2 ms |
9820 KB |
Output is correct |
10 |
Correct |
2 ms |
9820 KB |
Output is correct |
11 |
Correct |
21 ms |
9816 KB |
Output is correct |
12 |
Correct |
19 ms |
9816 KB |
Output is correct |
13 |
Correct |
29 ms |
9820 KB |
Output is correct |
14 |
Correct |
22 ms |
9816 KB |
Output is correct |
15 |
Correct |
2 ms |
9564 KB |
Output is correct |
16 |
Correct |
2 ms |
9820 KB |
Output is correct |
17 |
Correct |
2 ms |
9820 KB |
Output is correct |
18 |
Execution timed out |
3073 ms |
13520 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |