회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
4179번 어디가 문제인지 모르겠습니다.
4179번 - 불!
acs0209
2년 전
0
4179번 다른 질문글 테스트 케이스 넣어서 돌려도 답이 나오는데 어디가 문제인지 모르겠습니다.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Ps4179 { static int R; static int C; static int[] dirX = {1, 0, -1, 0}; static int[] dirY = {0, 1, 0, -1}; static char[][] mirror; static boolean[][] visited; static boolean[][] fireVisited; static int[][] escapeDays; static Queue<Node> queue = new LinkedList<>(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); R = Integer.parseInt(st.nextToken()); C = Integer.parseInt(st.nextToken()); escapeDays = new int[R][C]; visited = new boolean[R][C]; fireVisited = new boolean[R][C]; mirror = new char[R][C]; Node J = null; Node F = null; for (int i = 0; i < R; i++) { String s = br.readLine(); for (int j = 0; j < C; j++) { char value = s.charAt(j); mirror[i][j] = value; if (value == 'J') { J = new Node(i, j); visited[i][j] = true; escapeDays[i][j] = 1; queue.offer(J); } if (value == 'F') { F = new Node(i, j); fireVisited[i][j] = true; queue.offer(F); } } } while (!queue.isEmpty()) { Node node = queue.remove(); search(node.x, node.y); } boolean isImpossible = true; List<Integer> arr = new ArrayList<>(); for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if (mirror[i][j] == 'E') { arr.add(escapeDays[i][j]); isImpossible = false; } } } if (isImpossible) { System.out.println("IMPOSSIBLE"); return; } Collections.sort(arr); System.out.println(arr.get(0)); } static void search(int currentX, int currentY) { for (int i = 0; i < 4; i++) { int nextX = currentX + dirX[i]; int nextY = currentY + dirY[i]; if (0 <= nextX && nextX < R && 0 <= nextY && nextY < C) { if (mirror[currentX][currentY] == 'J' && mirror[nextX][nextY] == '.' && !visited[nextX][nextY]) { visited[nextX][nextY] = true; escapeDays[nextX][nextY] = escapeDays[currentX][currentY] + 1; mirror[nextX][nextY] = 'J'; queue.offer(new Node(nextX, nextY)); if (isEdge(nextX, nextY)) { mirror[nextX][nextY] = 'E'; } } if (mirror[currentX][currentY] == 'F' && mirror[nextX][nextY] != 'E' && !fireVisited[nextX][nextY]) { fireVisited[nextX][nextY] = true; mirror[nextX][nextY] = 'F'; queue.offer(new Node(nextX, nextY)); } } } } static boolean isEdge(int currentX, int currentY) { for (int i = 0; i < R; i++) { if (i == 0 || i == R - 1) { for (int j = 0; j < C; j++) { if (currentX == i && currentY == j) { return true; } } } else { if ((currentY == 0 && currentX == i) || (currentY == C - 1 && currentX == i)) { return true; } } } return false; } static class Node { int x; int y; Node(int x, int y) { this.x = x; this.y = y; } } }
chika
2년 전
0
안녕하세요! 반례 드릴게요 input) 5 5 ##### J#### .#### .#### ....F 3 3 ### J## ..F 두 케이스 전부다 답은 '1'입니다.
댓글을 작성하려면
로그인
해야 합니다.
acs0209 2년 전
4179번 다른 질문글 테스트 케이스 넣어서 돌려도 답이 나오는데 어디가 문제인지 모르겠습니다.