-
Notifications
You must be signed in to change notification settings - Fork 0
/
16235.cpp
80 lines (69 loc) · 1.92 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
#include<iostream>
#include<deque>
#include<algorithm>
#define N 15
using namespace std;
deque<int> tree[N][N];
int n, year, a[N][N], nut[N][N];
int xx[8]={-1, -1, -1, 0, 0, 1, 1, 1};
int yy[8]={-1, 0, 1, -1, 1, -1, 0, 1};
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int m, i, j;
cin >> n >> m >> year;
for(i=1; i<=n; i++){
for(j=1; j<=n; j++){
cin >> a[i][j];
nut[i][j]=5;
}
}
int a1, a2, a3;
for(i=1; i<=m; i++){
cin >> a1 >> a2 >> a3;
tree[a1][a2].push_back(a3);
}
for(i=1; i<=n; i++){
for(j=1; j<=n; j++)
sort(tree[i][j].begin(), tree[i][j].end());
}
for(int t=0; t<year; t++){
for(i=1; i<=n; i++){
for(j=1; j<=n; j++){
for(int k=0; k<tree[i][j].size(); k++){
if(nut[i][j]>=tree[i][j][k]) nut[i][j]-=tree[i][j][k]++;
else{
while(tree[i][j].size()>k){
nut[i][j]+=tree[i][j].back()/2;
tree[i][j].pop_back();
}
break;
}
}
nut[i][j]+=a[i][j];
}
}
for(i=1; i<=n; i++){
for(j=1; j<=n; j++){
for(int k=0; k<tree[i][j].size(); k++){
if(tree[i][j][k]%5==0){
for(int l=0; l<8; l++){
int nx=i+xx[l];
int ny=j+yy[l];
if(nx<1 || ny<1 || nx>n || ny>n) continue;
tree[nx][ny].push_front(1);
}
}
}
}
}
}
int ans=0;
for(i=1; i<=n; i++){
for(j=1; j<=n; j++)
ans+=tree[i][j].size();
}
cout << ans;
return 0;
}