#include <iostream>
#include "rainbow.h"
#define FOR(i,l,r,d) for(int i=(l); i<=(r); i+=(d))
int grid[51][51];
bool vis[51][51];
const int dx[4] = {1,-1,0,0};
const int dy[4] = {0,0,1,-1};
void init(int R, int C, int sr, int sc, int M, char *S) {
/// 0=land 1=river
FOR(i,1,R,1){
FOR(j,1,C,1){
grid[i][j] = 0;
}
}
grid[sr][sc] = 1;
int rptr=sr, cptr=sc;
FOR(i,0,M-1,1){
if(S[i]=='E') cptr++;
if(S[i]=='W') cptr--;
if(S[i]=='N') rptr--;
if(S[i]=='S') rptr++;
grid[rptr][cptr] = 1;
}
}
void dfs(int ar, int ac, int br, int bc, int cr, int cc){
vis[cr][cc] = 1;
FOR(i,0,3,1){
int nr = cr + dx[i];
int nc = cc + dy[i];
if(ar<=nr and nr<=br and ac<=nc and nc<=bc and grid[nr][nc]==0 and vis[nr][nc]==0){
dfs(ar, ac, br, bc, nr, nc);
}
}
}
int colour(int ar, int ac, int br, int bc) {
FOR(i,ar,br,1){
FOR(j,ac,bc,1){
vis[i][j] = 0;
}
}
int ret = 0;
FOR(i,ar,br,1){
FOR(j,ac,bc,1){
if(grid[i][j]==0 and vis[i][j]==0){
dfs(ar, ac, br, bc, i, j);
ret++;
}
}
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
8 ms |
360 KB |
Output is correct |
3 |
Correct |
21 ms |
488 KB |
Output is correct |
4 |
Correct |
18 ms |
424 KB |
Output is correct |
5 |
Correct |
6 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
14 ms |
480 KB |
Output is correct |
12 |
Correct |
15 ms |
440 KB |
Output is correct |
13 |
Correct |
8 ms |
332 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
8 ms |
360 KB |
Output is correct |
3 |
Correct |
21 ms |
488 KB |
Output is correct |
4 |
Correct |
18 ms |
424 KB |
Output is correct |
5 |
Correct |
6 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
14 ms |
480 KB |
Output is correct |
12 |
Correct |
15 ms |
440 KB |
Output is correct |
13 |
Correct |
8 ms |
332 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Runtime error |
2 ms |
716 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
8 ms |
360 KB |
Output is correct |
3 |
Correct |
21 ms |
488 KB |
Output is correct |
4 |
Correct |
18 ms |
424 KB |
Output is correct |
5 |
Correct |
6 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
14 ms |
480 KB |
Output is correct |
12 |
Correct |
15 ms |
440 KB |
Output is correct |
13 |
Correct |
8 ms |
332 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Runtime error |
2 ms |
716 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |