-
Notifications
You must be signed in to change notification settings - Fork 0
/
5547.cpp
53 lines (41 loc) · 1.06 KB
/
5547.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
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define X first
#define Y second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int dx[6] = {-1, -1, 0, 0, 1, 1};
int dy[6] = {0, 1, -1, 1, 0, 1};
int arr[103][103];
bool vis[103][103];
int main()
{
fastio;
int r, c;
cin >> c >> r;
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
cin >> arr[i][j];
queue<pii> q;
q.push({0, 0});
vis[0][0] = true;
int cnt = 0;
while (!q.empty())
{
auto cur = q.front();
q.pop();
for (int dir = 0; dir < 6; dir++)
{
int nx = cur.X + dx[dir];
int ny = cur.Y + dy[dir];
if(cur.X % 2 == 0 && dx[dir] != 0) ny--;
cnt += (arr[nx][ny] == 1);
if (nx < 0 || nx > r + 1 || ny < 0 || ny > c + 1) continue;
if (vis[nx][ny] || arr[nx][ny] == 1) continue;
q.push({nx, ny});
vis[nx][ny] = true;
}
}
cout << cnt << '\n';
}