#include "rainbow.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 1000 + 10;
const int INF = 1e9;
int n, m;
int vertex[MAXN][MAXN];
int edgesRight[MAXN][MAXN];
int edgesDown[MAXN][MAXN];
int sides[MAXN][MAXN];
bool t[MAXN][MAXN];
int minX = INF;
int maxX;
int minY = INF;
int maxY;
void init(int R, int C, int sr, int sc, int M, char *S)
{
n = R;
m = C;
for (int i = 0 ; i < M ; ++i)
{
minX = std::min(minX, sr);
maxX = std::max(maxX, sr);
minY = std::min(minY, sc);
maxY = std::max(maxY, sc);
t[sr][sc] = 1;
if (S[i] == 'N')
{
sr--;
} else if (S[i] == 'E')
{
sc++;
} else if (S[i] == 'S')
{
sr++;
} else if (S[i] == 'W')
{
sc--;
} else
{
assert(false);
}
}
t[sr][sc] = 1;
minX = std::min(minX, sr);
maxX = std::max(maxX, sr);
minY = std::min(minY, sc);
maxY = std::max(maxY, sc);
for (int i = 1 ; i <= n ; ++i)
{
for (int j = 1 ; j <= m ; ++j)
{
vertex[i][j] = t[i][j];
if (i < n) edgesDown[i][j] = t[i][j] || t[i + 1][j];
if (j < m) edgesRight[i][j] = t[i][j] || t[i][j + 1];
if (i < n && j < m) sides[i][j] = t[i][j] || t[i][j + 1] || t[i + 1][j] || t[i + 1][j + 1];
}
}
for (int i = 1 ; i <= n ; ++i)
{
for (int j = 1 ; j <= m ; ++j)
{
vertex[i][j] += vertex[i - 1][j] + vertex[i][j - 1] - vertex[i - 1][j - 1];
edgesRight[i][j] += edgesRight[i - 1][j] + edgesRight[i][j - 1] - edgesRight[i - 1][j - 1];
edgesDown[i][j] += edgesDown[i - 1][j] + edgesDown[i][j - 1] - edgesDown[i - 1][j - 1];
sides[i][j] += sides[i - 1][j] + sides[i][j - 1] - sides[i - 1][j - 1];
}
}
}
int calc(int prefix[][MAXN], int fromX, int fromY, int toX, int toY)
{
if (fromX > toX || fromY > toY) return 0;
return (toX - fromX + 1) * (toY - fromY + 1) - (prefix[toX][toY] - prefix[fromX - 1][toY] - prefix[toX][fromY - 1] + prefix[fromX - 1][fromY - 1]);
}
int colour(int ar, int ac, int br, int bc)
{
int res = 0;
res += calc(vertex, ar, ac, br, bc);
res += calc(sides, ar, ac, br - 1, bc - 1);
if (ar < minX && ac < minY && br > maxX && bc > maxY) // another side
{
res++;
}
res -= calc(edgesRight, ar, ac, br, bc - 1);
res -= calc(edgesDown, ar, ac, br - 1, bc);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8536 KB |
Output is correct |
3 |
Correct |
2 ms |
8536 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
8536 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8536 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
8536 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Incorrect |
45 ms |
9504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8536 KB |
Output is correct |
3 |
Correct |
2 ms |
8536 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
8536 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8536 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
8536 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
66 ms |
18076 KB |
Output is correct |
19 |
Correct |
42 ms |
9300 KB |
Output is correct |
20 |
Correct |
42 ms |
9296 KB |
Output is correct |
21 |
Correct |
43 ms |
9300 KB |
Output is correct |
22 |
Correct |
49 ms |
11600 KB |
Output is correct |
23 |
Correct |
43 ms |
9296 KB |
Output is correct |
24 |
Correct |
42 ms |
9296 KB |
Output is correct |
25 |
Correct |
42 ms |
9304 KB |
Output is correct |
26 |
Correct |
44 ms |
11344 KB |
Output is correct |
27 |
Correct |
61 ms |
17744 KB |
Output is correct |
28 |
Correct |
66 ms |
17740 KB |
Output is correct |
29 |
Correct |
70 ms |
17744 KB |
Output is correct |
30 |
Correct |
66 ms |
18000 KB |
Output is correct |
31 |
Correct |
3 ms |
8540 KB |
Output is correct |
32 |
Correct |
49 ms |
17812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8536 KB |
Output is correct |
3 |
Correct |
2 ms |
8536 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
8536 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8536 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
8536 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
66 ms |
18076 KB |
Output is correct |
19 |
Correct |
42 ms |
9300 KB |
Output is correct |
20 |
Correct |
42 ms |
9296 KB |
Output is correct |
21 |
Correct |
43 ms |
9300 KB |
Output is correct |
22 |
Correct |
49 ms |
11600 KB |
Output is correct |
23 |
Correct |
43 ms |
9296 KB |
Output is correct |
24 |
Correct |
42 ms |
9296 KB |
Output is correct |
25 |
Correct |
42 ms |
9304 KB |
Output is correct |
26 |
Correct |
44 ms |
11344 KB |
Output is correct |
27 |
Correct |
61 ms |
17744 KB |
Output is correct |
28 |
Correct |
66 ms |
17740 KB |
Output is correct |
29 |
Correct |
70 ms |
17744 KB |
Output is correct |
30 |
Correct |
66 ms |
18000 KB |
Output is correct |
31 |
Correct |
3 ms |
8540 KB |
Output is correct |
32 |
Correct |
49 ms |
17812 KB |
Output is correct |
33 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |