-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path344.cpp
More file actions
82 lines (75 loc) · 1.66 KB
/
Copy path344.cpp
File metadata and controls
82 lines (75 loc) · 1.66 KB
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
79
80
81
82
//
// Created by milad on 31.03.20.
//
in the
name of
God # include<bits / stdc++.h> using namespace std; #
define pb
push_back #
define slark
cerr << "slark" <<
endl;
#
define dagon
cout <<
endl;
#
define XX
first #
define YY
second #
define err(x)
cout << #x << " is: " << x <<
endl;
#
define Wait()
int _;
cin >>
_;
const int oo = 999999999;
const double PI = 3.1415931;
const double eps = 1e-9;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
const int maxN = 1000 + 10;
char mat[maxN][maxN];
bool mark[maxN][maxN];
int ans, ax[] = {1, 0, 0, -1}, ay[] = {0, 1, -1, 0}, level[maxN][maxN];
queue <pii> q;
int n, m;
bool valid(pii x) {
if (x.XX > 0 && x.YY > 0 && x.XX <= n && x.YY <= m) return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> mat[i][j];
if (mat[i][j] == 'X') {
ans++;
mark[i][j] = true;
q.push(pii(i, j));
}
}
}
while (!q.empty()) {
pii tmp = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
if (!mark[tmp.XX + ax[i]][tmp.YY + ay[i]] && valid(pii(tmp.XX + ax[i], tmp.YY + ay[i]))) {
level[tmp.XX + ax[i]][tmp.YY + ay[i]]++;
if (level[tmp.XX + ax[i]][tmp.YY + ay[i]] >= 2) {
ans++;
mark[tmp.XX + ax[i]][tmp.YY + ay[i]] = true;
q.push(pii(tmp.XX + ax[i], tmp.YY + ay[i]));
}
}
}
}
cout << ans << endl;
return 0;
}