-
Notifications
You must be signed in to change notification settings - Fork 0
/
2021febprob2.cpp
45 lines (34 loc) · 993 Bytes
/
2021febprob2.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
//
// Created by Tony on 12/18/2021.
//
#include <bits/stdc++.h>
using namespace std;
int grid[1005][1005];
bool cows[1005][1005];
int dx[5] = {0,0,1,-1};
int dy[5] = {1,-1,0,0};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
memset(grid,0,sizeof grid);
memset(cows,0,sizeof cows);
int ans = 0;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
cows[x][y] = 1;
for (int i = 0; i < 4; i++) {
pair<int,int> next = {x+dx[i],y+dy[i]};
if (next.first >= 0 && next.second >= 0) {
if (grid[next.first][next.second] == 2 && cows[next.first][next.second])
ans++;
else if (grid[next.first][next.second] == 3 && cows[next.first][next.second])
ans--;
grid[next.first][next.second]++;
}
}
cout << ans << endl;
}
}