#include "rainbow.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long BASE = 10000000LL;
vector<bool> used[2009]; int H, W, minx = (1 << 30), miny = (1 << 30), maxx = 0, maxy = 0;
vector<int> A[4][2009], A2[2009], A3[2009], A4[2009];
vector<pair<int, int>> G[4];
void putvector(int px, int py) {
G[0].push_back(make_pair(px, py));
G[1].push_back(make_pair(px, py - 1));
G[1].push_back(make_pair(px, py));
G[2].push_back(make_pair(px - 1, py));
G[2].push_back(make_pair(px, py));
G[3].push_back(make_pair(px - 1, py - 1));
G[3].push_back(make_pair(px - 1, py));
G[3].push_back(make_pair(px, py - 1));
G[3].push_back(make_pair(px, py));
}
void init(int R, int C, int sr, int sc, int M, char *S) {
H = R; W = C;
if (1LL * H*W <= BASE) {
for (int i = 0; i <= H; i++) used[i].resize(W + 1, true);
for (int i = 0; i <= H; i++) { for (int j = 0; j < 4; j++) A[j][i].resize(W + 1, 0); }
int cx = sr, cy = sc; used[cx][cy] = false; minx = cx; miny = cy; maxx = cx; maxy = cy;
for (int i = 0; i < M; i++) {
if (S[i] == 'E') cy++;
if (S[i] == 'W') cy--;
if (S[i] == 'N') cx--;
if (S[i] == 'S') cx++;
used[cx][cy] = false;
minx = min(minx, cx); maxx = max(maxx, cx);
miny = min(miny, cy); maxy = max(maxy, cy);
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) { if (used[i][j] == true) A[0][i][j] = 1; }
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W - 1; j++) { if (used[i][j] == true && used[i][j + 1] == true) A[1][i][j] = 1; }
}
for (int i = 1; i <= H - 1; i++) {
for (int j = 1; j <= W; j++) { if (used[i][j] == true && used[i + 1][j] == true) A[2][i][j] = 1; }
}
for (int i = 1; i <= H - 1; i++) {
for (int j = 1; j <= W - 1; j++) { if (used[i][j] == true && used[i][j + 1] == true && used[i + 1][j] == true && used[i + 1][j + 1] == true) A[3][i][j] = 1; }
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j <= H; j++) {
for (int k = 1; k <= W; k++) A[i][j][k] += A[i][j][k - 1];
}
for (int j = 1; j <= H; j++) {
for (int k = 0; k <= W; k++) A[i][j][k] += A[i][j - 1][k];
}
}
}
else {
int cx = sr, cy = sc; putvector(cx, cy);
for (int i = 0; i < M; i++) {
if (S[i] == 'E') cy++;
if (S[i] == 'W') cy--;
if (S[i] == 'N') cx--;
if (S[i] == 'S') cx++;
putvector(cx, cy);
minx = min(minx, cx); maxx = max(maxx, cx);
miny = min(miny, cy); maxy = max(maxy, cy);
}
for (int i = 0; i < 4; i++) {
sort(G[i].begin(), G[i].end());
G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end());
}
}
}
int ranged(int ty, int px, int py, int qx, int qy) {
if (px > qx || py > qy) return 0;
return A[ty][px - 1][py - 1] + A[ty][qx][qy] - A[ty][px - 1][qy] - A[ty][qx][py - 1];
}
long long big_ranged_attack(int ty, int px, int py, int qx, int qy) {
if (px > qx || py > py) return 0;
int rem = 0;
for (int i = 0; i < G[ty].size(); i++) {
if (px <= G[ty][i].first && G[ty][i].first <= qx && py <= G[ty][i].second && G[ty][i].second <= qy) rem++;
}
return rem;
}
int colour(int ar, int ac, int br, int bc) {
if (1LL * H*W <= BASE) {
int Z1 = ranged(0, ar, ac, br, bc);
int Z2 = ranged(1, ar, ac, br, bc - 1);
int Z3 = ranged(2, ar, ac, br - 1, bc);
int Z4 = ranged(3, ar, ac, br - 1, bc - 1);
int BONUS = 0; if (ar < minx && maxx < br && ac < miny && maxy < bc) BONUS = 1;
return (Z1 - Z2 - Z3 + Z4 + BONUS);
}
else {
long long V1 = br - ar + 1, V2 = bc - ac + 1;
long long Z1 = V1 * V2 - big_ranged_attack(0, ar, ac, br, bc);
long long Z2 = V1 * (V2 - 1) - big_ranged_attack(1, ar, ac, br, bc - 1);
long long Z3 = (V1 - 1) * V2 - big_ranged_attack(2, ar, ac, br - 1, bc);
long long Z4 = (V1 - 1) * (V2 - 1) - big_ranged_attack(3, ar, ac, br - 1, bc - 1);
long long BONUS = 0; if (ar < minx && maxx < br && ac < miny && maxy < bc) BONUS = 1;
return (Z1 - Z2 - Z3 + Z4 + BONUS);
}
}
Compilation message
rainbow.cpp: In function 'long long int big_ranged_attack(int, int, int, int, int)':
rainbow.cpp:85:20: warning: self-comparison always evaluates to false [-Wtautological-compare]
if (px > qx || py > py) return 0;
~~~^~~~
rainbow.cpp:88:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < G[ty].size(); i++) {
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
4 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
764 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
768 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
121 ms |
11000 KB |
Output is correct |
4 |
Correct |
118 ms |
10972 KB |
Output is correct |
5 |
Correct |
115 ms |
11000 KB |
Output is correct |
6 |
Correct |
111 ms |
10988 KB |
Output is correct |
7 |
Correct |
93 ms |
11000 KB |
Output is correct |
8 |
Correct |
129 ms |
11076 KB |
Output is correct |
9 |
Correct |
138 ms |
11140 KB |
Output is correct |
10 |
Correct |
153 ms |
10984 KB |
Output is correct |
11 |
Correct |
147 ms |
11000 KB |
Output is correct |
12 |
Correct |
87 ms |
11080 KB |
Output is correct |
13 |
Correct |
86 ms |
11000 KB |
Output is correct |
14 |
Correct |
80 ms |
11136 KB |
Output is correct |
15 |
Correct |
119 ms |
11128 KB |
Output is correct |
16 |
Correct |
117 ms |
10980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
75 ms |
8652 KB |
Output is correct |
3 |
Correct |
48 ms |
8656 KB |
Output is correct |
4 |
Correct |
42 ms |
8648 KB |
Output is correct |
5 |
Correct |
50 ms |
8268 KB |
Output is correct |
6 |
Correct |
87 ms |
8832 KB |
Output is correct |
7 |
Correct |
94 ms |
8812 KB |
Output is correct |
8 |
Correct |
14 ms |
5376 KB |
Output is correct |
9 |
Correct |
15 ms |
6016 KB |
Output is correct |
10 |
Correct |
48 ms |
4492 KB |
Output is correct |
11 |
Correct |
86 ms |
8692 KB |
Output is correct |
12 |
Correct |
80 ms |
8772 KB |
Output is correct |
13 |
Correct |
44 ms |
8648 KB |
Output is correct |
14 |
Correct |
47 ms |
8776 KB |
Output is correct |
15 |
Correct |
65 ms |
8276 KB |
Output is correct |
16 |
Correct |
97 ms |
8772 KB |
Output is correct |
17 |
Correct |
101 ms |
8704 KB |
Output is correct |
18 |
Correct |
80 ms |
8656 KB |
Output is correct |
19 |
Correct |
54 ms |
8756 KB |
Output is correct |
20 |
Correct |
56 ms |
8648 KB |
Output is correct |
21 |
Correct |
14 ms |
5376 KB |
Output is correct |
22 |
Correct |
15 ms |
6016 KB |
Output is correct |
23 |
Correct |
49 ms |
4492 KB |
Output is correct |
24 |
Correct |
97 ms |
8536 KB |
Output is correct |
25 |
Correct |
89 ms |
8648 KB |
Output is correct |
26 |
Correct |
45 ms |
8648 KB |
Output is correct |
27 |
Correct |
49 ms |
8740 KB |
Output is correct |
28 |
Correct |
60 ms |
8424 KB |
Output is correct |
29 |
Correct |
93 ms |
8644 KB |
Output is correct |
30 |
Correct |
91 ms |
8648 KB |
Output is correct |
31 |
Correct |
85 ms |
8712 KB |
Output is correct |
32 |
Correct |
62 ms |
8648 KB |
Output is correct |
33 |
Correct |
53 ms |
8708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
4 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
764 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
768 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
18 |
Correct |
138 ms |
17372 KB |
Output is correct |
19 |
Correct |
112 ms |
3072 KB |
Output is correct |
20 |
Correct |
73 ms |
1544 KB |
Output is correct |
21 |
Correct |
69 ms |
2204 KB |
Output is correct |
22 |
Correct |
105 ms |
3024 KB |
Output is correct |
23 |
Correct |
101 ms |
3064 KB |
Output is correct |
24 |
Correct |
77 ms |
1656 KB |
Output is correct |
25 |
Correct |
67 ms |
2076 KB |
Output is correct |
26 |
Correct |
86 ms |
3064 KB |
Output is correct |
27 |
Correct |
145 ms |
17400 KB |
Output is correct |
28 |
Correct |
155 ms |
17528 KB |
Output is correct |
29 |
Correct |
146 ms |
17528 KB |
Output is correct |
30 |
Correct |
152 ms |
17484 KB |
Output is correct |
31 |
Correct |
4 ms |
768 KB |
Output is correct |
32 |
Correct |
121 ms |
17488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
4 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
764 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
768 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
18 |
Correct |
138 ms |
17372 KB |
Output is correct |
19 |
Correct |
112 ms |
3072 KB |
Output is correct |
20 |
Correct |
73 ms |
1544 KB |
Output is correct |
21 |
Correct |
69 ms |
2204 KB |
Output is correct |
22 |
Correct |
105 ms |
3024 KB |
Output is correct |
23 |
Correct |
101 ms |
3064 KB |
Output is correct |
24 |
Correct |
77 ms |
1656 KB |
Output is correct |
25 |
Correct |
67 ms |
2076 KB |
Output is correct |
26 |
Correct |
86 ms |
3064 KB |
Output is correct |
27 |
Correct |
145 ms |
17400 KB |
Output is correct |
28 |
Correct |
155 ms |
17528 KB |
Output is correct |
29 |
Correct |
146 ms |
17528 KB |
Output is correct |
30 |
Correct |
152 ms |
17484 KB |
Output is correct |
31 |
Correct |
4 ms |
768 KB |
Output is correct |
32 |
Correct |
121 ms |
17488 KB |
Output is correct |
33 |
Correct |
75 ms |
8652 KB |
Output is correct |
34 |
Correct |
48 ms |
8656 KB |
Output is correct |
35 |
Correct |
42 ms |
8648 KB |
Output is correct |
36 |
Correct |
50 ms |
8268 KB |
Output is correct |
37 |
Correct |
87 ms |
8832 KB |
Output is correct |
38 |
Correct |
94 ms |
8812 KB |
Output is correct |
39 |
Correct |
14 ms |
5376 KB |
Output is correct |
40 |
Correct |
15 ms |
6016 KB |
Output is correct |
41 |
Correct |
48 ms |
4492 KB |
Output is correct |
42 |
Correct |
86 ms |
8692 KB |
Output is correct |
43 |
Correct |
80 ms |
8772 KB |
Output is correct |
44 |
Correct |
44 ms |
8648 KB |
Output is correct |
45 |
Correct |
47 ms |
8776 KB |
Output is correct |
46 |
Correct |
65 ms |
8276 KB |
Output is correct |
47 |
Correct |
97 ms |
8772 KB |
Output is correct |
48 |
Correct |
101 ms |
8704 KB |
Output is correct |
49 |
Correct |
80 ms |
8656 KB |
Output is correct |
50 |
Correct |
54 ms |
8756 KB |
Output is correct |
51 |
Correct |
56 ms |
8648 KB |
Output is correct |
52 |
Correct |
14 ms |
5376 KB |
Output is correct |
53 |
Correct |
15 ms |
6016 KB |
Output is correct |
54 |
Correct |
49 ms |
4492 KB |
Output is correct |
55 |
Correct |
97 ms |
8536 KB |
Output is correct |
56 |
Correct |
89 ms |
8648 KB |
Output is correct |
57 |
Correct |
45 ms |
8648 KB |
Output is correct |
58 |
Correct |
49 ms |
8740 KB |
Output is correct |
59 |
Correct |
60 ms |
8424 KB |
Output is correct |
60 |
Correct |
93 ms |
8644 KB |
Output is correct |
61 |
Correct |
91 ms |
8648 KB |
Output is correct |
62 |
Correct |
85 ms |
8712 KB |
Output is correct |
63 |
Correct |
62 ms |
8648 KB |
Output is correct |
64 |
Correct |
53 ms |
8708 KB |
Output is correct |
65 |
Correct |
98 ms |
6116 KB |
Output is correct |
66 |
Correct |
104 ms |
6692 KB |
Output is correct |
67 |
Execution timed out |
3059 ms |
4844 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |