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
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int w, h;
int dy[6] = {-1, 0,+1,+1, 0,-1};
int dx[6] = { 0,-1, 0,+1,+1,+1};
int dy2[6] = {-1, 0,+1,+1, 0,-1};
int dx2[6] = {-1,-1,-1, 0,+1, 0};
bool can(int y,int x) {
if(0 <= y && y < h + 2 && 0 <= x && x < w + 2) return true;
return false;
}
int main() {
cin >> w >> h;
vector< vector<int> > v(h + 2, vector<int>(w + 2));
rep(i, h) {
rep(j, w) cin >> v[i+1][j+1];
}
int sy = 0, sx = 0;
queue<P> que;
que.push(mp(sy, sx));
bool used[105][105];
memset(used, 0, sizeof(used));
used[sy][sx] = true;
int ans = 0;
while(que.size()) {
P p = que.front();
que.pop();
rep(i, 6) {
int y, x;
if(p.first % 2 == 0) {
y = p.first + dy2[i];
x = p.second + dx2[i];
} else {
y = p.first + dy[i];
x = p.second + dx[i];
}
if(can(y, x)) {
if(v[y][x] == 1) {
ans++;
} else if(!used[y][x]) {
used[y][x] = true;
que.push(mp(y, x));
}
}
}
}
cout << ans << endl;
return 0;
}
|