#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std ;
int n , m , x , y ;
string s ;
map < int , map <int , int>> vis ;
map <char , int> f , a ;
void init(int R, int C, int sr, int sc, int M, char *S) {
f['N'] = -1 ; f['S'] = 1 ;
a['E'] = 1 ; a['W'] = -1 ;
n = R ; m = C ; x = sr , y = sc ; s = S ;
for ( int i = 0 ; i < M ; i ++ ) x += f[s[i]] , y += a[s[i]] , vis[x][y] = 2 ;
vis[sr][sc] = 2 ;
}
int q , w ;
void dfs ( int i , int j ){
vis[i][j] = 1 ;
for ( int x = -1 ; x < 2 ; x ++ ){
for ( int y = -1 ; y < 2 ; y ++ ){
if ( x*y != 0 ) continue ;
if ( x+i>=q && y+j >= w && x+i <= n && y+j <= m && vis[i+x][y+j] == 0 ) dfs(i+x,y+j) ;
}
}
}
int colour(int ar, int ac, int br, int bc) {
int ans = 0 ;
for ( int i = ar ; i <= br ; i ++ ){
for ( int j = ac ; j <= bc ; j ++ ){
if ( vis[i][j] == 1 ) vis[i][j] = 0 ;
}
}
for ( int i = ar ; i <= br ; i ++ ){
for ( int j = ac ; j <= bc ; j ++ ){
if ( vis[i][j] == 0 ){
n= br ; m = bc ;
q = ar ; w = ac ;
//cout << i << ' ' << j << endl;
ans ++ ; dfs(i,j) ;
}
}
}
return ans ;
}
/*
static int R, C, M, Q;
static int sr, sc;
static char S[100000 + 5];
int main() {
scanf("%d %d %d %d", &R, &C, &M, &Q);
scanf("%d %d", &sr, &sc);
if (M > 0) {
scanf(" %s ", S);
}
init(R, C, sr, sc, M, S);
int query;
for (query = 0; query < Q; query++) {
int ar, ac, br, bc;
scanf("%d %d %d %d", &ar, &ac, &br, &bc);
printf("%d\n", colour(ar, ac, br, bc));
}
return 0;
}
//*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
96 ms |
572 KB |
Output is correct |
3 |
Correct |
279 ms |
604 KB |
Output is correct |
4 |
Correct |
284 ms |
764 KB |
Output is correct |
5 |
Correct |
94 ms |
344 KB |
Output is correct |
6 |
Correct |
0 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 |
218 ms |
604 KB |
Output is correct |
12 |
Correct |
181 ms |
604 KB |
Output is correct |
13 |
Correct |
157 ms |
604 KB |
Output is correct |
14 |
Correct |
116 ms |
560 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
3039 ms |
47856 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
2912 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
96 ms |
572 KB |
Output is correct |
3 |
Correct |
279 ms |
604 KB |
Output is correct |
4 |
Correct |
284 ms |
764 KB |
Output is correct |
5 |
Correct |
94 ms |
344 KB |
Output is correct |
6 |
Correct |
0 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 |
218 ms |
604 KB |
Output is correct |
12 |
Correct |
181 ms |
604 KB |
Output is correct |
13 |
Correct |
157 ms |
604 KB |
Output is correct |
14 |
Correct |
116 ms |
560 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
3037 ms |
52720 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
96 ms |
572 KB |
Output is correct |
3 |
Correct |
279 ms |
604 KB |
Output is correct |
4 |
Correct |
284 ms |
764 KB |
Output is correct |
5 |
Correct |
94 ms |
344 KB |
Output is correct |
6 |
Correct |
0 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 |
218 ms |
604 KB |
Output is correct |
12 |
Correct |
181 ms |
604 KB |
Output is correct |
13 |
Correct |
157 ms |
604 KB |
Output is correct |
14 |
Correct |
116 ms |
560 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
3037 ms |
52720 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |