# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
410034 | PikaChu999 | Tracks in the Snow (BOI13_tracks) | Java | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
5 8
FFR.....
.FRRR...
.FFFFF..
..RRRFFR
.....FFF
*/
import java.util.*;
import java.io.*;
public class Main {
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;
}
}