/*
5 8
FFR.....
.FRRR...
.FFFFF..
..RRRFFR
.....FFF
*/
import java.util.*;
import java.io.*;
public class tracks {
public static int height;
public static int width;
public static String[][] grid;
public static int res = 0;
public static int[] xCoors = {0,0,-1,1};
public static int[] yCoors = {1,-1,0,0};
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer details = new StringTokenizer(br.readLine());
height = Integer.parseInt(details.nextToken());
width = Integer.parseInt(details.nextToken());
grid = new String[height][width];
for(int x = 0; x < height; x++){
String row = br.readLine();
for(int y = 0; y < width; y++){
grid[x][y] = String.valueOf(row.charAt(y));
}
}
floodfill();
System.out.println(res);
br.close();
}
public static void floodfill(){
boolean[][] seen = new boolean[height][width];
for(int a = 0; a < height; a++){
for(int b = 0; b < width; b++){
if(!seen[a][b] && !grid[a][b].equals(".")){
res++;
String animal = grid[a][b];
boolean otherAnimal = false;
Queue<Coord> tree = new LinkedList<Coord>();
tree.add(new Coord(a, b));
while(!tree.isEmpty()){
Coord current = tree.poll();
if(!seen[current.x][current.y]){
if(!grid[current.x][current.y].equals(animal)) otherAnimal = true;
System.out.println(current + " " + grid[current.x][current.y]);
seen[current.x][current.y] = true;
for(int c = 0; c < 4; c++){
int xCoord = current.x + xCoors[c];
int yCoord = current.y + yCoors[c];
if(xCoord < 0 || yCoord < 0 || xCoord >= height || yCoord >= width || grid[xCoord][yCoord].equals(".")) continue;
tree.add(new Coord(xCoord, yCoord));
}
}
}
if(otherAnimal) res++;
}
}
}
}
}
class Coord{
int x;
int y;
public Coord(int xC, int yC){
x = xC;
y = yC;
}
public String toString(){
return x + " " + y;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2075 ms |
38724 KB |
Time limit exceeded |
2 |
Incorrect |
190 ms |
11744 KB |
Output isn't correct |
3 |
Incorrect |
331 ms |
12056 KB |
Output isn't correct |
4 |
Incorrect |
1635 ms |
28652 KB |
Output isn't correct |
5 |
Incorrect |
876 ms |
21272 KB |
Output isn't correct |
6 |
Incorrect |
194 ms |
12020 KB |
Output isn't correct |
7 |
Incorrect |
311 ms |
12124 KB |
Output isn't correct |
8 |
Incorrect |
541 ms |
15940 KB |
Output isn't correct |
9 |
Incorrect |
325 ms |
13948 KB |
Output isn't correct |
10 |
Incorrect |
1008 ms |
20628 KB |
Output isn't correct |
11 |
Incorrect |
1092 ms |
19604 KB |
Output isn't correct |
12 |
Incorrect |
1272 ms |
22536 KB |
Output isn't correct |
13 |
Incorrect |
888 ms |
21416 KB |
Output isn't correct |
14 |
Incorrect |
877 ms |
21500 KB |
Output isn't correct |
15 |
Incorrect |
1885 ms |
39012 KB |
Output isn't correct |
16 |
Execution timed out |
2053 ms |
38708 KB |
Time limit exceeded |
17 |
Incorrect |
1475 ms |
37448 KB |
Output isn't correct |
18 |
Incorrect |
1631 ms |
28776 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
886 ms |
19900 KB |
Output isn't correct |
2 |
Execution timed out |
2076 ms |
144216 KB |
Time limit exceeded |
3 |
Execution timed out |
2083 ms |
596184 KB |
Time limit exceeded |
4 |
Execution timed out |
2072 ms |
239236 KB |
Time limit exceeded |
5 |
Execution timed out |
2084 ms |
480644 KB |
Time limit exceeded |
6 |
Execution timed out |
2032 ms |
558432 KB |
Time limit exceeded |
7 |
Incorrect |
961 ms |
20036 KB |
Output isn't correct |
8 |
Incorrect |
914 ms |
20044 KB |
Output isn't correct |
9 |
Incorrect |
988 ms |
20280 KB |
Output isn't correct |
10 |
Incorrect |
895 ms |
18668 KB |
Output isn't correct |
11 |
Incorrect |
857 ms |
19868 KB |
Output isn't correct |
12 |
Incorrect |
807 ms |
17612 KB |
Output isn't correct |
13 |
Execution timed out |
2048 ms |
144276 KB |
Time limit exceeded |
14 |
Execution timed out |
2072 ms |
87396 KB |
Time limit exceeded |
15 |
Execution timed out |
2079 ms |
94132 KB |
Time limit exceeded |
16 |
Execution timed out |
2077 ms |
73484 KB |
Time limit exceeded |
17 |
Execution timed out |
2067 ms |
255992 KB |
Time limit exceeded |
18 |
Execution timed out |
2090 ms |
251204 KB |
Time limit exceeded |
19 |
Execution timed out |
2094 ms |
241780 KB |
Time limit exceeded |
20 |
Execution timed out |
2072 ms |
225064 KB |
Time limit exceeded |
21 |
Execution timed out |
2073 ms |
481336 KB |
Time limit exceeded |
22 |
Execution timed out |
2088 ms |
480652 KB |
Time limit exceeded |
23 |
Execution timed out |
2084 ms |
477556 KB |
Time limit exceeded |
24 |
Execution timed out |
2086 ms |
481616 KB |
Time limit exceeded |
25 |
Execution timed out |
2085 ms |
582820 KB |
Time limit exceeded |
26 |
Execution timed out |
2080 ms |
542420 KB |
Time limit exceeded |
27 |
Execution timed out |
2061 ms |
573516 KB |
Time limit exceeded |
28 |
Execution timed out |
2054 ms |
552016 KB |
Time limit exceeded |
29 |
Execution timed out |
2114 ms |
573176 KB |
Time limit exceeded |
30 |
Execution timed out |
2112 ms |
598280 KB |
Time limit exceeded |
31 |
Execution timed out |
2109 ms |
512712 KB |
Time limit exceeded |
32 |
Execution timed out |
2036 ms |
489256 KB |
Time limit exceeded |