-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaintbarn.txt
50 lines (46 loc) · 1.76 KB
/
paintbarn.txt
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
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class paintbarn {
public static void main(String[] args) throws IOException {
BufferedReader f=new BufferedReader(new FileReader("paintbarn.in"));
final int square =1001;
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("paintbarn.out")));
int[][] barn = new int[square][square];
int[][] painted = new int[square][square];
StringTokenizer st = new StringTokenizer(f.readLine());
int paintNum = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int[][] paints = new int[paintNum][4];
for(int i=0; i<paintNum; i++){
st = new StringTokenizer(f.readLine());
paints[i][0]=Integer.parseInt(st.nextToken());
paints[i][1]=Integer.parseInt(st.nextToken());
paints[i][2]= Integer.parseInt(st.nextToken());
paints[i][3]= Integer.parseInt(st.nextToken());
}
for(int i=0; i<paintNum; i++){
for(int j=paints[i][1]; j<paints[i][3]; j++){
barn[j][paints[i][0]]=barn[j][paints[i][0]] +1;
barn[j][paints[i][2]]=barn[j][paints[i][2]]-1;
}
}
for(int i=0; i<square; i++){
int owo = 0;
for(int j=0; j<square; j++){
owo +=barn[i][j];
painted[i][j]=owo;
}
}
int count =0;
for(int i=0; i<square; i++){
for(int j=0; j<square; j++){
if(painted[i][j]==K){
count++;
}
}
}
out.println(count);
out.close();
}
}