-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheese.java
More file actions
65 lines (59 loc) · 1.43 KB
/
Cheese.java
File metadata and controls
65 lines (59 loc) · 1.43 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
import java.util.*;
import java.io.*;
import java.util.StringTokenizer;
public class Cheese {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
boolean[][][] cheese = new boolean[n][n][n];
int ans = 0;
for(int i=0; i<q; i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int z = Integer.parseInt(st.nextToken());
cheese[x][y][z] = true;
int contiguousX = 0;
int contiguousY = 0;
int contiguousZ = 0;
int k = 0;
while(k < n) {
while(k < n && cheese[k][y][z] == true) {
contiguousX++;
k++;
}
ans += Math.max(0, contiguousX - n + 1);
contiguousX = 0;
k++;
}
//finished X
k = 0;
while(k < n) {
while(k < n && cheese[x][k][z] == true) {
contiguousY++;
k++;
}
ans += Math.max(0, contiguousY - n + 1);
contiguousY = 0;
k++;
}
//finished Y
k = 0;
while(k < n) {
while(k < n && cheese[x][y][k] == true) {
contiguousZ++;
k++;
}
ans += Math.max(0, contiguousZ - n + 1);
contiguousZ = 0;
k++;
}
//finished Z
pw.println(ans);
}
pw.close();
}
}