회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
고수님들 도와주세요
14502번 - 연구소
tjam1723
2년 전
0
맞게 한거 같은데 본문의 테스트 케이스도 결과가 이상하게 나오네요.. ㅠㅠ
import java.util.*; class point { int x; int y; point (int x,int y) { x = this.x; y = this.y; } } public class Main { static int arr[][]; static int copy[][]; static int virus[][]; static int xx[] = {-1,1,0,0}; static int yy[] = {0,0,-1,1}; static int result = Integer.MIN_VALUE; static int N,M; public static void main (String args[]) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); M = sc.nextInt(); arr = new int[N][M]; copy = new int[N][M]; for (int i=0; i<N; i++) { for (int j=0; j<M; j++) { arr[i][j] = copy[i][j] = sc.nextInt(); } } sc.close (); for (int i=0; i<N; i++) { for (int j=0; j<M; j++) { if (copy[i][j]==0) { arr[i][j]=1; dfs(1); arr[i][j]=0; } } } System.out.println(result); } public static void dfs (int cnt) { if (cnt==3) { bfs(); return; } for (int i=0; i<N; i++) { for (int j=0; j<M; j++) { if (arr[i][j]==0) { arr[i][j]=1; dfs(cnt+1); arr[i][j]=0; } } } } static void bfs () { virus = new int[N][M]; for (int i=0; i<N; i++) { for (int j=0; j<M; j++) { virus[i][j] = arr[i][j]; } } Queue<point>q = new LinkedList<point>(); for (int i=0; i<N; i++) { for (int j=0; j<M; j++) { if (virus[i][j]==2) q.add(new point(i,j)); } } while (!q.isEmpty()) { point p = q.remove(); for (int i=0; i<4; i++) { int nx = p.x+xx[i]; int ny = p.y+yy[i]; if (nx>=0 && nx<N && ny>=0 && ny<M) { if (virus[nx][ny]==0) { virus[nx][ny]=2; q.add(new point(nx,ny)); } } } } answer(virus); } static void answer(int virus[][]) { int count = 0; for (int i=0; i<N; i++) { for (int j=0; j<M; j++) { if (virus[i][j]==0) count++; } } result = Math.max(count, result); } }
댓글을 작성하려면
로그인
해야 합니다.
tjam1723 2년 전
맞게 한거 같은데 본문의 테스트 케이스도 결과가 이상하게 나오네요.. ㅠㅠ