#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
bool a[51][51];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int dir[256];
int bx1 = INT32_MAX, bx2 = INT32_MIN, by1 = INT32_MAX, by2 = INT32_MIN;
void upd(int x, int y){
bx1 = min(bx1, x);
bx2 = max(bx2, x);
by1 = min(by1, y);
by2 = max(by2, y);
}
void init(int R, int C, int sr, int sc, int M, char *S) {
dir['E'] = 0;
dir['W'] = 1;
dir['S'] = 2;
dir['N'] = 3;
a[sr][sc] = true;
upd(sr, sc);
for(int i = 0; i < M; i++){
sr += dx[dir[S[i]]];
sc += dy[dir[S[i]]];
a[sr][sc] = true;
upd(sr, sc);
}
}
int colour(int ar, int ac, int br, int bc) {
int x1 = ar, x2 = br, y1 = ac, y2 = bc;
int V = 0, E = 0, SQ = 0;
for(int i = x1; i <= x2; i++){
for(int j = y1; j <= y2; j++){
V += !a[i][j];
}
}
for(int i = x1; i <= x2; i++){
for(int j = y1; j < y2; j++){
E += !a[i][j] && !a[i][j + 1];
}
}
for(int i = x1; i < x2; i++){
for(int j = y1; j <= y2; j++){
E += !a[i + 1][j] && !a[i][j];
}
}
for(int i = x1; i < x2; i++){
for(int j = y1; j < y2; j++){
SQ += !a[i][j] && !a[i + 1][j] && !a[i][j + 1] && !a[i + 1][j + 1];
}
}
return V - E + SQ + (x1 < bx1 && bx2 < x2 && y1 < by1 && by2 < y2);
}
Compilation message
rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:29:19: warning: array subscript has type 'char' [-Wchar-subscripts]
29 | sr += dx[dir[S[i]]];
| ~~~^
rainbow.cpp:30:19: warning: array subscript has type 'char' [-Wchar-subscripts]
30 | sc += dy[dir[S[i]]];
| ~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
340 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
4 ms |
320 KB |
Output is correct |
14 |
Correct |
6 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Runtime error |
2 ms |
724 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
340 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
4 ms |
320 KB |
Output is correct |
14 |
Correct |
6 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Execution timed out |
3065 ms |
1068 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
340 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
4 ms |
320 KB |
Output is correct |
14 |
Correct |
6 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Execution timed out |
3065 ms |
1068 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |