회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
[JAVA] 반례를 못찾겠습니다ㅠㅠ
7569번 - 토마토
yujun93
3년 전
0
질문글 반례 다 해본것 같은데 못찾겠습니다ㅠㅠ
10프로 채점가서 틀리네요....
반례 무엇이 있을까요??
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 { public static void main(String[] args) throws IOException { BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(rd.readLine()); int y = Integer.parseInt(st.nextToken()); int x = Integer.parseInt(st.nextToken()); int h = Integer.parseInt(st.nextToken()); int[][] map = new int[x * h][y]; Queue<int[]> queue = new LinkedList<>(); int[] dx = {1, -1, 0 ,0}; int[] dy = {0, 0, 1 ,-1}; for (int i = 0; i < x * h; i++) { StringTokenizer st2 = new StringTokenizer(rd.readLine()); for (int j = 0; j < y; j++) { map[i][j] = Integer.parseInt(st2.nextToken()); if (map[i][j] == 1) { queue.offer(new int[] {i, j}); } } } if (queue.size() == x * h * y) { System.out.println("1"); System.exit(0); } int result = 0; while (! queue.isEmpty()) { int qs = queue.size(); for (int i = 0; i < qs; i++) { int[] z = queue.poll(); for (int j = 0; j < 4; j++) { int j1 = z[0] + dx[j]; int j2 = z[1] + dy[j]; if (j1 >= 0 && j1 < x * h && j2 >= 0 && j2 < y) { if (map[j1][j2] == 0) { queue.offer(new int[] {j1, j2}); map[j1][j2] = map[z[0]][z[1]] + 1; result = map[j1][j2]; } } } if (z[0] + x < x * h) { if (map[z[0] + x][z[1]] == 0) { queue.offer(new int[] {z[0] + x, z[1]}); map[z[0] + x][z[1]] = map[z[0]][z[1]] + 1; result = map[z[0] + x][z[1]]; } } if (z[0] - x >= 0) { if (map[z[0] - x][z[1]] == 0) { queue.offer(new int[] {z[0] - x, z[1]}); map[z[0] - x][z[1]] = map[z[0]][z[1]] + 1; result = map[z[0] - x][z[1]]; } } } } for (int i = 0; i < x * h; i++) { for (int j = 0; j < y; j++) { if (map[i][j] == 0) { System.out.println("-1"); System.exit(0); } } } System.out.println(result); } }
댓글을 작성하려면
로그인
해야 합니다.
yujun93 3년 전
질문글 반례 다 해본것 같은데 못찾겠습니다ㅠㅠ
10프로 채점가서 틀리네요....
반례 무엇이 있을까요??