-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16235.java
More file actions
115 lines (93 loc) · 2.45 KB
/
16235.java
File metadata and controls
115 lines (93 loc) · 2.45 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main {
static class Tree implements Comparable<Tree>{
int x;
int y;
int age;
Tree(int x, int y, int age) {this.x=x; this.y=y; this.age=age;}
@Override
public int compareTo(Tree o) {
if(this.age > o.age)
return 1;
else if(this.age < o.age)
return -1;
else
return 0;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[][] eatable = new int[n][n];
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
eatable[i][j] = 5;
int[][] gain = new int[n][n];
for(int i=0; i<n; i++) {
st = new StringTokenizer(br.readLine());
for(int j=0; j<n; j++) {
gain[i][j] = Integer.parseInt(st.nextToken());
}
}
ArrayList<Tree> alive = new ArrayList<>(m);
for(int i=0; i<m; i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int age = Integer.parseInt(st.nextToken());
alive.add(new Tree(x-1, y-1, age));
}
Collections.sort(alive);
ArrayList<Tree> dead;
while(k-- > 0) {
dead = new ArrayList<>();
ArrayList<Tree> alive_new = new ArrayList<>();
// 봄
for(Tree t : alive) {
if(t.age <= eatable[t.x][t.y]) {
eatable[t.x][t.y] -= t.age;
t.age++;
alive_new.add(t);
} else {
dead.add(t);
}
}
// 여름
for(Tree t : dead) {
eatable[t.x][t.y] += t.age/2;
}
// 가을
ArrayList<Tree> born = new ArrayList<>();
for(Tree t : alive_new) {
if(t.age%5 == 0) {
for(int i=0; i<8; i++) {
int x = t.x+dx[i];
int y = t.y+dy[i];
if(x<0 || x>=n || y<0 || y>=n)
continue;
born.add(new Tree(x, y, 1));
}
}
}
born.addAll(alive_new);
alive = born;
// 겨울
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
eatable[i][j] += gain[i][j];
}
}
}
System.out.println(alive.size());
}
static int[] dx = {1, 0, -1, 0, 1, 1, -1, -1};
static int[] dy = {0, 1, 0, -1, 1, -1, 1, -1};
}