#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 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 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 |
2 ms |
8536 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
3 ms |
8536 KB |
Output is correct |
12 |
Correct |
2 ms |
8792 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
8536 KB |
Output is correct |
17 |
Correct |
2 ms |
8536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8536 KB |
Output is correct |
3 |
Incorrect |
42 ms |
9560 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 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 |
2 ms |
8536 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
3 ms |
8536 KB |
Output is correct |
12 |
Correct |
2 ms |
8792 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
8536 KB |
Output is correct |
17 |
Correct |
2 ms |
8536 KB |
Output is correct |
18 |
Correct |
68 ms |
20816 KB |
Output is correct |
19 |
Correct |
43 ms |
12112 KB |
Output is correct |
20 |
Correct |
40 ms |
12056 KB |
Output is correct |
21 |
Correct |
42 ms |
12044 KB |
Output is correct |
22 |
Correct |
49 ms |
14356 KB |
Output is correct |
23 |
Correct |
41 ms |
12124 KB |
Output is correct |
24 |
Correct |
41 ms |
12064 KB |
Output is correct |
25 |
Correct |
40 ms |
12120 KB |
Output is correct |
26 |
Correct |
42 ms |
14160 KB |
Output is correct |
27 |
Correct |
66 ms |
20816 KB |
Output is correct |
28 |
Correct |
71 ms |
20796 KB |
Output is correct |
29 |
Correct |
68 ms |
20560 KB |
Output is correct |
30 |
Correct |
69 ms |
20816 KB |
Output is correct |
31 |
Correct |
3 ms |
8536 KB |
Output is correct |
32 |
Correct |
52 ms |
20560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 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 |
2 ms |
8536 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
3 ms |
8536 KB |
Output is correct |
12 |
Correct |
2 ms |
8792 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
8536 KB |
Output is correct |
17 |
Correct |
2 ms |
8536 KB |
Output is correct |
18 |
Correct |
68 ms |
20816 KB |
Output is correct |
19 |
Correct |
43 ms |
12112 KB |
Output is correct |
20 |
Correct |
40 ms |
12056 KB |
Output is correct |
21 |
Correct |
42 ms |
12044 KB |
Output is correct |
22 |
Correct |
49 ms |
14356 KB |
Output is correct |
23 |
Correct |
41 ms |
12124 KB |
Output is correct |
24 |
Correct |
41 ms |
12064 KB |
Output is correct |
25 |
Correct |
40 ms |
12120 KB |
Output is correct |
26 |
Correct |
42 ms |
14160 KB |
Output is correct |
27 |
Correct |
66 ms |
20816 KB |
Output is correct |
28 |
Correct |
71 ms |
20796 KB |
Output is correct |
29 |
Correct |
68 ms |
20560 KB |
Output is correct |
30 |
Correct |
69 ms |
20816 KB |
Output is correct |
31 |
Correct |
3 ms |
8536 KB |
Output is correct |
32 |
Correct |
52 ms |
20560 KB |
Output is correct |
33 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |