회원가입
로그인
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
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
틀렸습니다 출력이 왜 뜨는지 모르겠습니다..
2636번 - 치즈
bigtiger92
3년 전
0
14개정도의 테스트케이스를 돌려보았습니다 혹시 문제점 잡아주실분 계신가요
import java.util.Scanner; public class Main { static int R, C; static int[][] map; static int[][] cheezeMap; static boolean[][] visited; static int[] dy = { -1, 1, 0, 0 }; static int[] dx = { 0, 0, -1, 1 }; static int sy, sx; static int result; static int cheezeCount, meltingTime; static boolean go; public static void main(String[] args) { Scanner scan = new Scanner(System.in); R = scan.nextInt(); C = scan.nextInt(); map = new int[R][C]; cheezeMap = new int[R][C]; visited = new boolean[R][C]; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { cheezeMap[i][j] = scan.nextInt(); if (cheezeMap[i][j] == 1) { go = true; } } } if (go) { visited[0][0] = true; cheezeMap[0][0] = 2; findAir(0, 0); // for (int i = 0; i < R; i++) { // for (int j = 0; j < C; j++) { // System.out.print(map[i][j]+" "); // } // System.out.println(); // } while (go) { go = false; arrayCopy(map, cheezeMap); visited = new boolean[R][C]; meltingTime++; result = cheezeCount; cheezeCount = 0; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if(map[i][j] == 0 && !visited[i][j]) { for (int d = 0; d < 4; d++) { int ny = i + dy[d]; int nx = j + dx[d]; if (ny >= 0 && ny < R && nx >= 0 && nx < C && map[ny][nx] == 2) { cheezeMap[i][j] = 2; map[i][j] = 2; break; } } findAir2(i,j); } } } // for (int i = 0; i < R; i++) { // for (int j = 0; j < C; j++) { // System.out.print(map[i][j]+"\t"); // } // System.out.println(); // } // System.out.println(); // System.out.println(); visited = new boolean[R][C]; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if (map[i][j] == 1 && !visited[i][j]) { go = true; cheezeCount++; visited[i][j] = true; for (int d = 0; d < 4; d++) { int ny = i + dy[d]; int nx = j + dx[d]; if (ny >= 0 && ny < R && nx >= 0 && nx < C && map[ny][nx] == 2) { cheezeMap[i][j] = 2; break; } } dfs(i, j); } } } } } else { meltingTime = 1; result = 0; } System.out.print(meltingTime-1 + "\n" + result); } public static void dfs(int y, int x) { for (int d = 0; d < 4; d++) { int ny = y + dy[d]; int nx = x + dx[d]; if (ny > 0 && ny < R - 1 && nx > 0 && nx < C - 1 && map[ny][nx] == 1 && !visited[ny][nx]) { visited[ny][nx] = true; cheezeCount++; for (int e = 0; e < 4; e++) { int cy = ny + dy[e]; int cx = nx + dx[e]; if (cy >= 0 && cy < R && cx >= 0 && cx < C && map[cy][cx] == 2) { cheezeMap[ny][nx] = 2; break; } } dfs(ny, nx); } } } public static void findAir(int y, int x) { for (int d = 0; d < 4; d++) { int ny = y + dy[d]; int nx = x + dx[d]; if (ny >= 0 && ny < R && nx >= 0 && nx < C && cheezeMap[ny][nx] == 0 && !visited[ny][nx]) { cheezeMap[ny][nx] = 2; visited[ny][nx] = true; findAir(ny, nx); } } } public static void findAir2(int y, int x) { for (int d = 0; d < 4; d++) { int ny = y + dy[d]; int nx = x + dx[d]; if (ny >= 0 && ny < R && nx >= 0 && nx < C && cheezeMap[ny][nx] == 0 && !visited[ny][nx]) { visited[ny][nx] = true; for (int e = 0; e < 4; e++) { int cy = ny + dy[e]; int cx = nx + dx[e]; if (cy >= 0 && cy < R && cx >= 0 && cx < C && map[cy][cx] == 2) { cheezeMap[ny][nx] = 2; map[ny][nx] = 2; break; } } findAir2(ny, nx); } } } public static void arrayCopy(int[][] a, int[][] b) { for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { a[i][j] = b[i][j]; } } } }
댓글을 작성하려면
로그인
해야 합니다.
bigtiger92 3년 전
14개정도의 테스트케이스를 돌려보았습니다 혹시 문제점 잡아주실분 계신가요