-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps535.cpp
More file actions
48 lines (36 loc) · 793 Bytes
/
Copy pathneps535.cpp
File metadata and controls
48 lines (36 loc) · 793 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
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Contest : Neps
* Problem : 535 - Colorindo
* Link : https://neps.academy/br/exercise/535
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
typedef pair<int, int> pii;
int n, m, x, y, k, a, b, cnt;
vector<vector<int>> grid;
int pos[] = {0, 1, -1};
void dfs(int i, int j) {
grid[i][j] = 1;
cnt++;
for (auto &lin : pos) {
int x = lin + i;
for (auto &col : pos) {
y = col + j;
if (x >= 1 && x <= n && y >= 1 && y <= m && !grid[x][y]) { dfs(x, y); }
}
}
}
int main() {
fastio
cin >> n >> m >> x >> y >> k;
grid.assign(n + 1, vector<int>(m + 1, 0));
cnt = 0;
while (k--) {
cin >> a >> b;
grid[n - a + 1][b] = -1;
}
dfs(n - x + 1, y);
cout << cnt << '\n';
return 0;
}