회원가입
로그인
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
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
[JAVA] 질문게시판의 모든 반례가 맞는것 같아 보이지만, 런타임에러입니다.
7576번 - 토마토
joenggyu0
5년 전
0
혹시 반례를 부탁드립니다
메모리 문제는 아닌것같고, 제가 놓친 반례가 있는 듯 한데, 부탁드립니다!!
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main { static int N, M; // 2 ~ 1000 static final int TOMATO = 1; static final int LESS_RIPE_TOMATO = 0; static final int NOT_IN_TOMATO = -1; static final int[] dx = {0, 0, -1, 1}; static final int[] dy = {1, -1, 0, 0}; static int[][][] map; static boolean[][] isVisited; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); Queue<Point> tomatoBasket = new LinkedList<>(); M = Integer.parseInt(st.nextToken()); //col 가로 N = Integer.parseInt(st.nextToken()); //row 세로 int step = 0; map = new int[N][M][(M * N) + 1]; isVisited = new boolean[N][M]; for (int i = 0; i < N; i++) { st = new StringTokenizer(br.readLine()); for (int j = 0; j < M; j++) { map[i][j][0] = Integer.parseInt(st.nextToken()); if (map[i][j][0] == TOMATO) { tomatoBasket.add(new Point(i, j)); isVisited[i][j] = true; } } } while (!tomatoBasket.isEmpty()) { step += 1; if (step > 0) { for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { map[i][j][step] = map[i][j][step - 1]; } } } int size = tomatoBasket.size(); for (int i = 0; i < size; i++) { Point tomato = tomatoBasket.poll(); for (int j = 0; j < 4; j++) { int nextRow = tomato.row + dx[j]; int nextCol = tomato.col + dy[j]; if (nextRow < 0 || nextRow >= N || nextCol < 0 || nextCol >= M) continue; if (isVisited[nextRow][nextCol]) continue; if (map[nextRow][nextCol][step] == NOT_IN_TOMATO || map[nextRow][nextCol][step] == TOMATO) continue; map[nextRow][nextCol][step] = TOMATO; isVisited[nextRow][nextCol] = true; tomatoBasket.add(new Point(nextRow, nextCol)); } } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (map[i][j][step] == LESS_RIPE_TOMATO) { System.out.println(NOT_IN_TOMATO); return; } } } System.out.println(step - 1); } } class Point { int row; int col; public Point(int row, int col) { this.row = row; this.col = col; } }
댓글을 작성하려면
로그인
해야 합니다.
joenggyu0 5년 전
혹시 반례를 부탁드립니다
메모리 문제는 아닌것같고, 제가 놓친 반례가 있는 듯 한데, 부탁드립니다!!