#include "rainbow.h"
#define N 1000
#define M 1000
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int vv[N][M], ee1[N][M], ee2[N][M], ff[N][M], imin, imax, jmin, jmax;
void init(int n, int m, int i_, int j_, int l, char *dd) {
int h, i, j;
i_--, j_--;
if (n > 1000 || m > 1000) /* :( */
return;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
vv[i][j] = 1;
imin = imax = i_, jmin = jmax = j_;
vv[i_][j_] = 0;
for (h = 0; h < l; h++) {
if (dd[h] == 'N')
i_--;
else if (dd[h] == 'S')
i_++;
else if (dd[h] == 'W')
j_--;
else
j_++;
imin = min(imin, i_), imax = max(imax, i_);
jmin = min(jmin, j_), jmax = max(jmax, j_);
vv[i_][j_] = 0;
}
for (i = 0; i < n; i++)
for (j = 1; j < m; j++)
ee1[i][j] = vv[i][j] && vv[i][j - 1];
for (i = 1; i < n; i++)
for (j = 0; j < m; j++)
ee2[i][j] = vv[i][j] && vv[i - 1][j];
for (i = 1; i < n; i++)
for (j = 1; j < m; j++)
ff[i][j] = vv[i][j] && vv[i][j - 1] && vv[i - 1][j] && vv[i - 1][j - 1];
for (i = 0; i < n; i++)
for (j = 1; j < m; j++)
vv[i][j] += vv[i][j - 1];
for (j = 0; j < m; j++)
for (i = 1; i < n; i++)
vv[i][j] += vv[i - 1][j];
for (i = 0; i < n; i++)
for (j = 1; j < m; j++)
ee1[i][j] += ee1[i][j - 1];
for (j = 0; j < m; j++)
for (i = 1; i < n; i++)
ee1[i][j] += ee1[i - 1][j];
for (i = 0; i < n; i++)
for (j = 1; j < m; j++)
ee2[i][j] += ee2[i][j - 1];
for (j = 0; j < m; j++)
for (i = 1; i < n; i++)
ee2[i][j] += ee2[i - 1][j];
for (i = 0; i < n; i++)
for (j = 1; j < m; j++)
ff[i][j] += ff[i][j - 1];
for (j = 0; j < m; j++)
for (i = 1; i < n; i++)
ff[i][j] += ff[i - 1][j];
}
int rect(int aa[][M], int i1, int j1, int i2, int j2) {
return i1 > i2 || j1 > j2 ? 0 : aa[i2][j2] - (j1 == 0 ? 0 : aa[i2][j1 - 1]) - (i1 == 0 ? 0 : aa[i1 - 1][j2]) + (i1 == 0 || j1 == 0 ? 0 : aa[i1 - 1][j1 - 1]);
}
int colour(int i1, int j1, int i2, int j2) {
int v, e, f;
i1--, j1--, i2--, j2--;
v = rect(vv, i1, j1, i2, j2);
e = rect(ee1, i1, j1 + 1, i2, j2) + rect(ee2, i1 + 1, j1, i2, j2);
f = rect(ff, i1 + 1, j1 + 1, i2, j2);
if (i1 < imin && imax < i2 && j1 < jmin && jmax < j2)
f++;
return v - e + f;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
1132 KB |
Output is correct |
3 |
Correct |
2 ms |
1132 KB |
Output is correct |
4 |
Correct |
2 ms |
1132 KB |
Output is correct |
5 |
Correct |
2 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
1132 KB |
Output is correct |
12 |
Correct |
2 ms |
1132 KB |
Output is correct |
13 |
Correct |
2 ms |
1280 KB |
Output is correct |
14 |
Correct |
2 ms |
1132 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Incorrect |
59 ms |
4076 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
3 ms |
748 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
1132 KB |
Output is correct |
3 |
Correct |
2 ms |
1132 KB |
Output is correct |
4 |
Correct |
2 ms |
1132 KB |
Output is correct |
5 |
Correct |
2 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
1132 KB |
Output is correct |
12 |
Correct |
2 ms |
1132 KB |
Output is correct |
13 |
Correct |
2 ms |
1280 KB |
Output is correct |
14 |
Correct |
2 ms |
1132 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
119 ms |
19592 KB |
Output is correct |
19 |
Correct |
87 ms |
5416 KB |
Output is correct |
20 |
Correct |
58 ms |
5460 KB |
Output is correct |
21 |
Correct |
61 ms |
6892 KB |
Output is correct |
22 |
Correct |
71 ms |
8684 KB |
Output is correct |
23 |
Correct |
63 ms |
5356 KB |
Output is correct |
24 |
Correct |
76 ms |
5356 KB |
Output is correct |
25 |
Correct |
63 ms |
7020 KB |
Output is correct |
26 |
Correct |
67 ms |
8684 KB |
Output is correct |
27 |
Correct |
111 ms |
19564 KB |
Output is correct |
28 |
Correct |
124 ms |
19692 KB |
Output is correct |
29 |
Correct |
118 ms |
19564 KB |
Output is correct |
30 |
Correct |
113 ms |
19548 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
95 ms |
19564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
1132 KB |
Output is correct |
3 |
Correct |
2 ms |
1132 KB |
Output is correct |
4 |
Correct |
2 ms |
1132 KB |
Output is correct |
5 |
Correct |
2 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
1132 KB |
Output is correct |
12 |
Correct |
2 ms |
1132 KB |
Output is correct |
13 |
Correct |
2 ms |
1280 KB |
Output is correct |
14 |
Correct |
2 ms |
1132 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
119 ms |
19592 KB |
Output is correct |
19 |
Correct |
87 ms |
5416 KB |
Output is correct |
20 |
Correct |
58 ms |
5460 KB |
Output is correct |
21 |
Correct |
61 ms |
6892 KB |
Output is correct |
22 |
Correct |
71 ms |
8684 KB |
Output is correct |
23 |
Correct |
63 ms |
5356 KB |
Output is correct |
24 |
Correct |
76 ms |
5356 KB |
Output is correct |
25 |
Correct |
63 ms |
7020 KB |
Output is correct |
26 |
Correct |
67 ms |
8684 KB |
Output is correct |
27 |
Correct |
111 ms |
19564 KB |
Output is correct |
28 |
Correct |
124 ms |
19692 KB |
Output is correct |
29 |
Correct |
118 ms |
19564 KB |
Output is correct |
30 |
Correct |
113 ms |
19548 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
95 ms |
19564 KB |
Output is correct |
33 |
Runtime error |
3 ms |
748 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |