회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
올라와 있는 예제데이터를 다 통과하였지만 틀렸습니다가 나옵니다
15683번 - 감시
qdae123
4년 전
0
어디가 틀렸는지 확인받고 싶습니다 ㅠㅠ
import java.util.Scanner; /** * 백준 15683. 감시 * * @author ksh * * 1~5번 CCTV * > 감시 방향에 있는 칸 전체 감시 * > 벽은 통과 불가 * > 감시 못하면 사각지대 * > 회전은 90도 -> 1~5번의 상, 하, 좌, 우 방향을 다 만들어 놓고 모든 케이스 계산 (중복 순열 4^5) * > CCTV는 CCTV 통과 가능 * * 사각지대 최소 크기는? */ public class Main { static class Dir { int[] dr; int[] dc; Dir(int[] dr, int[] dc) { this.dr = dr; this.dc = dc; } } static class CCTV { Dir[] dir; CCTV (Dir[] dir) { this.dir = dir; } } // CCTV1 // 상 - 상 // 하 - 하 // 좌 - 좌 // 우 - 우 static CCTV cctv1 = new CCTV( new Dir[] { new Dir(new int[]{-1}, new int[]{0}), new Dir(new int[]{1}, new int[]{0}), new Dir(new int[]{0}, new int[]{-1}), new Dir(new int[]{0}, new int[]{1}) } ); //CCTV2 // 상 - 상, 하 // 하 - 상, 하 // 좌 - 좌, 우 // 우 - 좌, 우 static CCTV cctv2 = new CCTV( new Dir[] { new Dir(new int[]{-1, 1}, new int[]{0, 0}), new Dir(new int[]{-1, 1}, new int[]{0, 0}), new Dir(new int[]{0, 0}, new int[]{-1, 1}), new Dir(new int[]{0, 0}, new int[]{-1, 1}) } ); //CCTV3 // 상 - 상, 우 // 하 - 하, 우 // 좌 - 하, 좌 // 우 - 상, 좌 static CCTV cctv3 = new CCTV( new Dir[] { new Dir(new int[]{-1, 0}, new int[]{0, 1}), new Dir(new int[]{1, 0}, new int[]{0, 1}), new Dir(new int[]{1, 0}, new int[]{0, -1}), new Dir(new int[]{-1, 0}, new int[]{0, -1}) } ); //CCTV4 // 상 - 상, 좌, 우 // 하 - 하, 좌, 우 // 좌 - 상, 하, 좌 // 우 - 상, 하, 우 static CCTV cctv4 = new CCTV( new Dir[] { new Dir(new int[]{-1, 0, 0}, new int[]{0, -1, 1}), new Dir(new int[]{-1, 0, 0}, new int[]{0, -1, 1}), new Dir(new int[]{-1, 1, 0}, new int[]{0, 0, -1}), new Dir(new int[]{-1, 1, 0}, new int[]{0, 0, 1}) } ); // CCTV5 // 상 - 상, 하, 좌, 우 // 하 - 상, 하, 좌, 우 // 좌 - 상, 하, 좌, 우 // 우 - 상, 하, 좌, 우 static CCTV cctv5 = new CCTV( new Dir[] { new Dir(new int[]{-1, 1, 0, 0}, new int[]{0, 0, -1, 1}), new Dir(new int[]{-1, 1, 0, 0}, new int[]{0, 0, -1, 1}), new Dir(new int[]{-1, 1, 0, 0}, new int[]{0, 0, -1, 1}), new Dir(new int[]{-1, 1, 0, 0}, new int[]{0, 0, -1, 1}) } ); static CCTV[] cctvList = {cctv1, cctv2, cctv3, cctv4, cctv5}; static int N, M; static int[][] map; static int Cnt; static int wall; static int ans = Integer.MAX_VALUE; public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); M = sc.nextInt(); map = new int[N][M]; for(int r = 0; r < N; r++) { for(int c = 0; c < M; c++) { map[r][c] = sc.nextInt(); if(map[r][c] != 0 && map[r][c] !=6) { Cnt++; } if(map[r][c] == 6) { wall++; } } } sel = new int[Cnt]; reperm(0); System.out.println(ans); } static int[] sel; static void reperm(int s_idx) { if(s_idx == Cnt) { int cctvCnt = -1; visited = new boolean[N][M]; for(int r = 0; r < N; r++) { for(int c = 0; c < M; c++) { if(map[r][c] != 0 && map[r][c] !=6) { cctvCnt++; solve(r, c, map[r][c]-1, sel[cctvCnt]); } } } int temp = 0; for(int r = 0; r < N; r++) { for(int c = 0; c < M; c++) { if(!visited[r][c]) { temp++; } } // System.out.println(Arrays.toString(visited[r])); } // System.out.println(temp-Cnt-wall); ans = Math.min(ans, temp-Cnt-wall); return; } for(int i = 0; i <4; i++) { sel[s_idx] = i; reperm(s_idx+1); } } static boolean[][] visited; static void solve(int r, int c, int cctvType, int direction) { CCTV cur = cctvList[cctvType]; Dir dir = cur.dir[direction]; int dirSize = dir.dr.length; for(int i = 0; i < dirSize; i++) { int nr = r + dir.dr[i]; int nc = c + dir.dc[i]; while (nr >= 0 && nr < N && nc >= 0 && nc <M) { if(map[nr][nc] == 6) { break; } if(map[nr][nc] == 0) { visited[nr][nc] = true; } nr = nr + dir.dr[i]; nc = nc + dir.dc[i]; } } } }
댓글을 작성하려면
로그인
해야 합니다.
qdae123 4년 전
어디가 틀렸는지 확인받고 싶습니다 ㅠㅠ