-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16235.cpp
92 lines (87 loc) · 2.75 KB
/
16235.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
86
87
88
89
90
91
92
//
// Created by kdongha on 2019/12/16.
//
#include <bits/stdc++.h>
int N, M, K;
struct Land {
int food = 5;
int fill;
int dead = 0;
std::deque<int> prevTree;
std::deque<int> nextTree;
};
Land land[11][11];
int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};
bool inside(int x, int y) {
return x > 0 && x <= N && y > 0 && y <= N;
}
void solve() {
std::cin >> N >> M >> K;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
std::cin >> land[i][j].fill;
}
}
for (int i = 0; i < M; i++) {
int x, y, z;
std::cin >> x >> y >> z;
land[x][y].prevTree.push_back(z);
}
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= N; y++) {
std::sort(land[x][y].prevTree.begin(), land[x][y].prevTree.end());
}
}
for (int k = 0; k < K; k++) {
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= N; y++) {
while (!land[x][y].prevTree.empty()) {
int tree = land[x][y].prevTree.front();
land[x][y].prevTree.pop_front();
if (land[x][y].food >= tree) {
land[x][y].food -= tree;
land[x][y].nextTree.push_back(tree + 1);
if ((tree + 1) % 5 == 0) {
for (int d = 0; d < 4; d++) {
int nx = x + dx[d];
int ny = y + dy[d];
if (inside(nx, ny)) {
land[nx][ny].nextTree.push_front(1);
}
}
for (int d = 4; d < 8; d++) {
int nx = x + dx[d];
int ny = y + dy[d];
if (inside(nx, ny)) {
land[nx][ny].prevTree.push_front(1);
}
}
}
} else {
land[x][y].dead += tree / 2;
}
}
land[x][y].food += land[x][y].dead;
land[x][y].dead = 0;
land[x][y].food += land[x][y].fill;
land[x][y].prevTree = land[x][y].nextTree;
land[x][y].nextTree = std::deque<int>();
}
}
}
int cnt = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
cnt += land[i][j].prevTree.size();
}
}
std::cout << cnt;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
solve();
return 0;
}