This repository was archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlake.java
More file actions
86 lines (80 loc) · 2.16 KB
/
lake.java
File metadata and controls
86 lines (80 loc) · 2.16 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
import java.io.*;
import java.util.*;
public class lake {
public static int findin2D(ArrayList<int[]> a,int[] wanna) {
for(int i=0;i<a.size();i++) {
if(a.get(i).equals(wanna)) {
return i;
}
}
return -1;
}
public static void main(String[] args) throws Exception {
// TODO a TODO a TODO
BufferedReader f=new BufferedReader(new FileReader("lake.9.in"));
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("lake.out")));
StringTokenizer st=new StringTokenizer(f.readLine());
//throw new Exception("Not finished");
int x=Integer.parseInt(st.nextToken())+1;int y=Integer.parseInt(st.nextToken())+1;int z=Integer.parseInt(st.nextToken());
ArrayList<int[]> al=new ArrayList<int[]>();
int[] build= {0,0};
for(int i=0;i<z;i++) {
st=new StringTokenizer(f.readLine());
build[0]=Integer.parseInt(st.nextToken());
build[1]=Integer.parseInt(st.nextToken());
al.add(build.clone());
}
int[][] map=new int[x][y];
for(int i=0;i<z;i++) {
build=al.get(i);
map[build[0]][build[1]]=1;
}
int[][] logic={{1,0},{-1,0},{0,1},{0,-1}};
Stack<Integer> X=new Stack<Integer>();Stack<Integer> Y=new Stack<Integer>();
int answer=-1;
int RAM=0;
while(!(al.isEmpty())) {
//System.out.println("DEBUG:"+x+" "+y+" "+z);
RAM=0;
X.clear();
Y.clear();
build=al.remove(0);
X.add(build[0]);
Y.add(build[1]);
while(!(X.isEmpty())) {
//System.out.println("DEBUG2:"+x+" "+y+" "+z);
x=X.pop();
y=Y.pop();
try {
if(map[x][y]==1) {
map[x][y]=-2;
for(int j=0;j<logic.length;j++) {
build=logic[j];
X.push(x+build[0]);
Y.push(y+build[1]);
}
RAM++;
}
}catch(Exception e) {
//e.printStackTrace();
//System.out.println("INFO:OUT OF BOUNDS");
}
/*
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
for(int i=0;i<map.length;i++) {
for(int j=0;j<map[0].length;j++) {
System.out.print(map[i][j]+" ");
}
System.out.println();
}
//Thread.sleep(2000);
*
*/
}
if(RAM>answer) {
answer=RAM;
}
}
System.out.println(answer);
}
}