회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
반례 좀 찾아주세요 ㅜㅜㅜ 12퍼 틀림
2636번 - 치즈
namuemue
2년 전
0
게시판에 있는 모든 반례 다 돌려봤는데 올바르게 나옵니다...
어떤 반례가 있을까요
도와주세요 !
/* * 1. (0,0) 좌표에서 치즈 밖의 공간을 -1로 바꿔줌 * 2. 1 상하좌우에 -1이 하나라도 있으면 1을 -1로 바꿔줌 * 3. 판에 1이 없을 때 까지 반복 * * * * */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.StringTokenizer; class Cheese{ int x; int y; public Cheese(int x, int y) { super(); this.x = x; this.y = y; } } public class BOJ_치즈 { static int N, M, Ans, chee, noCheese; static int[][] arr; static boolean[][] v; static int[] dx = {0,0,-1,1}; static int[] dy = {-1,1,0,0}; static List<Cheese> list; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; st = new StringTokenizer(br.readLine()); N = Integer.parseInt(st.nextToken()); M = Integer.parseInt(st.nextToken()); arr = new int[N][M]; //list = new ArrayList<>(); Ans = 0; chee = 0; noCheese=0; for(int i=0; i<N; i++) { st = new StringTokenizer(br.readLine()); for(int j=0; j<M; j++) { arr[i][j] = Integer.parseInt(st.nextToken()); if(arr[i][j] == 1) noCheese++; } } while(noCheese !=0) { list = new ArrayList<>(); v = new boolean[N][M]; L: for(int i=0; i<N; i++) { for(int j=0; j<M; j++) { if(arr[i][j]==0 || (arr[i][j]==1 && (i==N-1 || j == M-1)) ) { change_background(i,j); break L; } } } v = new boolean[N][M]; // print(); for(int i=0; i<N; i++) { for(int j=0; j<M; j++) { if(arr[i][j]==1 && !v[i][j]) { melting_cheese(i,j); } } } // 치즈 녹이기 for(int i=0; i<list.size(); i++) { arr[list.get(i).x][list.get(i).y] = -1; noCheese--; } Ans++; chee = list.size(); } System.out.println(Ans); System.out.println(chee); } // 녹일 치즈를 한번에 어딘가에 담아서 녹여야함 private static void melting_cheese(int x, int y) { Queue<Cheese> queue = new LinkedList<>(); queue.offer(new Cheese(x, y)); v[x][y]= true; while(!queue.isEmpty()) { Cheese c = queue.poll(); if(check_border(c.x, c.y)) { list.add(new Cheese(c.x, c.y)); } for(int i=0; i<4; i++) { int nx = c.x + dx[i]; int ny = c.y + dy[i]; if(nx>=0 && ny>=0 && nx<N && ny<M && !v[nx][ny]) { if(arr[nx][ny] == 1) { queue.offer(new Cheese(nx, ny)); v[nx][ny] = true; } } } } } private static boolean check_border(int x, int y) { for(int i=0; i<4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if(nx>=0 && ny>=0 && nx<N && ny<M) { if(arr[nx][ny] == -1) return true; } } return false; } private static void print() { StringBuilder sb = new StringBuilder(); for(int i=0; i<N; i++) { for(int j=0; j<M; j++) { sb.append(arr[i][j]).append(" "); } sb.append("\n"); } System.out.print(sb); } private static void change_background(int x, int y) { v = new boolean[N][M]; Queue<Cheese> queue = new LinkedList<>(); queue.offer(new Cheese(x, y)); v[x][y] = true; while(!queue.isEmpty()) { Cheese c = queue.poll(); arr[c.x][c.y] = -1; for(int i=0; i<4; i++) { int nx = c.x + dx[i]; int ny = c.y + dy[i]; if(nx>=0 && ny>=0 && nx<N && ny<M && !v[nx][ny]) { if(arr[nx][ny] == 0) { queue.offer(new Cheese(nx, ny)); v[nx][ny] = true; } } } } } // private static boolean check_one() { // // // 1이 있으면 false를 리턴 // for(int i=0; i<N; i++) // { // for(int j=0; j<M; j++) // { // if(arr[i][j] == 1) // { // return false; // } // } // } // // return true; // // } }
댓글을 작성하려면
로그인
해야 합니다.
namuemue 2년 전
게시판에 있는 모든 반례 다 돌려봤는데 올바르게 나옵니다...
어떤 반례가 있을까요
도와주세요 !