-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABC_182_E.cpp
78 lines (63 loc) · 1.09 KB
/
ABC_182_E.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <vector>
#include <cstring>
#include <utility>
using namespace std;
vector<pair<int, int> > bulbs;
int grid[1502][1502];
int h, w, n, m;
const int direction[][2] = { 1, 0, -1, 0, 0, 1, 0, -1 };
int main() {
cin >> h >> w >> n >> m;
// set border to -1
for (int i = 0; i <= h; i++)
{
grid[i][0] = -1;
grid[i][w + 1] = -1;
}
for (int i = 0; i <= w; i++)
{
grid[0][i] = -1;
grid[h + 1][i] = -1;
}
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
grid[a][b] = 1;
bulbs.push_back(make_pair(a, b));
}
for (int i = 0; i < m; i++)
{
int c, d;
cin >> c >> d;
grid[c][d] = -1;
}
int ans = n;
for (int i = 0; i < n; i++)
{
int a = bulbs[i].first;
int b = bulbs[i].second;
for (int d = 0; d < 4; d++)
{
int x = a, y = b;
int cnt = 1;
while (true)
{
int nx = x + direction[d][0] * cnt;
int ny = y + direction[d][1] * cnt;
if (grid[nx][ny] == -1 || grid[nx][ny] == 1)
{
break;
}
if (grid[nx][ny] == 0)
{
ans++;
}
grid[nx][ny] = 2;
cnt++;
}
}
}
cout << ans << endl;
}