회원가입
로그인
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
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
고수님들 왜 틀렸는지 알려주세요 ㅠㅠ (JAVA)
7576번 - 토마토
tlaaksen12
6년 전
0
틀린 테스트 케이스좀 알려주세요 ㅠㅠ
뭐가 문제일까요 ㅠㅠ
import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static int[][] box; static boolean[][] checked; static int blankcnt=0; static int n,m,day; static int[] dx = {0,0,-1,1}; //위, 아래, 왼쪽, 오른쪽 static int[] dy = {-1,1,0,0}; static Queue<Point> que = new LinkedList<>(); public static void main(String[] args) { Scanner scan = new Scanner(System.in); n = scan.nextInt(); m = scan.nextInt(); box = new int[n][m]; //박스 생성 checked = new boolean[n][m]; //체크했던것인지 확인을 위한 배열 for(int i=0; i<n; i++){ //박스에 토마토 넣기 및 빈공간 갯수파악 for (int j=0; j<m; j++){ int istomato = scan.nextInt(); if(istomato==0){ blankcnt++; }else if(istomato == -1){ box[i][j] = -1; }else{ box[i][j] = 1; que.offer(new Point(i,j)); checked[i][j] = true; } } } scan.close(); day = -1; bfs(); if(blankcnt==0){ System.out.println(day); }else{ System.out.println(-1); } } static void bfs(){ while(!que.isEmpty()){ int quesize = que.size(); for(int i=0; i< quesize; i++){ Point p = que.poll(); for(int j=0; j<4; j++){ int px = p.x+dx[j]; int py = p.y+dy[j]; if(px<0||py<0||px==n||py==m||checked[px][py]==true||box[px][py]==-1)continue; checked[px][py]=true; que.offer(new Point(px,py)); blankcnt--; } } day++; } } } class Point{ int x; int y; Point(int x, int y){ this.x = x; this.y = y; } }
댓글을 작성하려면
로그인
해야 합니다.
tlaaksen12 6년 전
틀린 테스트 케이스좀 알려주세요 ㅠㅠ
뭐가 문제일까요 ㅠㅠ