-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.cpp
More file actions
36 lines (30 loc) · 813 Bytes
/
test2.cpp
File metadata and controls
36 lines (30 loc) · 813 Bytes
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
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> ii;
const int N = 1010;
int n, g[N][N];
bool cows[N][N];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
cin >> n;
int ans = 0;
for (int i = 0; i < n; i++) {
int x, y; cin >> x >> y;
cows[x][y] = true;
for (int j = 0; j < 4; j++) {
int nx = x + dx[j];
int ny = y + dy[j];
if (nx >= 0 && nx <= 1000 && ny >= 0 && ny <= 1000) {
g[nx][ny]++;
if (cows[nx][ny] && g[nx][ny] == 3) ans++;
if (cows[nx][ny] && g[nx][ny] == 4) ans--;
}
}
if (g[x][y] == 3) ans++;
cout << ans << endl;
}
}