-
Notifications
You must be signed in to change notification settings - Fork 185
/
d.cc
62 lines (59 loc) · 1.44 KB
/
d.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// https://abc086.contest.atcoder.jp/tasks/arc089_b
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<vi> vvi;
int main() {
int n, k;
cin >> n >> k;
vi x(n);
vi y(n);
vc c(n);
vvi v(k * 2);
for (int i = 0; i < k * 2; i++) v[i] = vi(k * 2, 0);
for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> c[i];
for (int i = 0; i < n; i++) {
if (c[i] == 'W') y[i] += k;
x[i] %= 2 * k;
y[i] %= 2 * k;
v[y[i]][x[i]]++;
}
for (int i = 1; i < 2 * k; i++) {
v[0][i] += v[0][i - 1];
}
for (int i = 1; i < 2 * k; i++) {
v[i][0] += v[i - 1][0];
}
for (int i = 1; i < 2 * k; i++) {
for (int j = 1; j < 2 * k; j++) {
v[i][j] += v[i][j - 1] + v[i - 1][j] - v[i - 1][j - 1];
}
}
int m = 0;
for (int i = - k; i < k; i++)
for (int j = - k; j < k; j++) {
int s = 0;
for (int a = i, d = 0; a <= 2 * k; a += k, d++) {
for (int b = j - (d%2) * k; b <= 2 * k; b += 2 *k) {
if (a <= -k) continue;
if (b <= -k) continue;
int yi = min(a + k - 1, 2 * k - 1);
int xi = min(b + k - 1, 2 * k - 1);
s += v[yi][xi];
if (a > 0) {
s -= v[a - 1][xi];
}
if (b > 0) {
s -= v[yi][b - 1];
}
if (a > 0 && b > 0) {
s += v[a - 1][b - 1];
}
}
}
m = max(m, s);
}
cout << m << endl;
}