-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeeproblem.cpp
85 lines (75 loc) · 1.64 KB
/
beeproblem.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
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
83
84
85
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <climits>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
using ii = pair<ll,ll>;
vector<vector<char>> MAP;
priority_queue<ll> Q;
ll h,n,m;
ll nb(int r, int c) {
ll cnt = 1;
for (int i=-1; i<=1; i++) {
int cc = c + i;
if (cc < 0 || cc >= m) continue;
if (MAP[r][cc] == '#') continue;
MAP[r][cc] = '#';
cnt += nb(r,cc);
}
int i, iend;
if (r%2) i = 0;
else i = -1;
iend = i+2;
for (; i < iend; i++) {
for (int j = -1; j < 2; j += 2) {
int rr = r+j;
int cc = c+i;
if (rr < 0 || rr >= n) continue;
if (cc < 0 || cc >= m) continue;
if (MAP[rr][cc] == '#') continue;
MAP[rr][cc] = '#';
cnt += nb(rr,cc);
}
}
return cnt;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("1.in","r",stdin);
cin >> h >>n >> m;
MAP.assign(n, vector<char>(m));
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
cin >> MAP[i][j];
}
}
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
if (MAP[i][j] == '.') {
MAP[i][j] = '#';
ll c = nb(i,j);
Q.push(c);
}
}
}
ll ans = 0;
while (h>0) {
h -= Q.top();
Q.pop();
ans++;
}
cout << ans;
}