회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
java 반례부탁드릴게요 ㅠㅠㅠ
1012번 - 유기농 배추
ghkdwlgns612
2년 전
0
게시판 테스트케이스 대부분 통과하는데 25%에서 계속막히네요.. 도움부탁드려요 ㅠㅠㅠ
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); int[] res_arr = new int[T]; for (int test = 0; test < T; test++) { int M = sc.nextInt(); int N = sc.nextInt(); int res = 0; int num = sc.nextInt(); int[][] arr = new int[N + 2][M + 2]; for (int i = 0; i < num; i++) { int m = sc.nextInt(); int n = sc.nextInt(); arr[n + 1][m + 1] = 1; } for (int i = 0; i < N + 2; i++) { for (int j = 0; j < M + 2; j++) { if (arr[i][j] != 1) arr[i][j] = 0; } } for (int i = 1; i < N + 1; i++) { for (int j = 1; j < M + 1; j++) { if (arr[i][j] == 1) { arr[i][j] = 0; arr = ft_dfs(arr,i,j); res++; } } } res_arr[test] = res; } for(int i = 0; i<T; i++) System.out.println(res_arr[i]); } public static int[][] ft_dfs(int[][] arr, int tmp_x, int tmp_y) { while (true) { if (arr[tmp_x - 1][tmp_y] == 1) { arr[tmp_x - 1][tmp_y] = 0; arr = ft_dfs(arr, tmp_x-1,tmp_y); } else if (arr[tmp_x][tmp_y - 1] == 1) { arr[tmp_x][tmp_y - 1] = 0; arr = ft_dfs(arr, tmp_x-1,tmp_y); } else if (arr[tmp_x][tmp_y + 1] == 1) { arr[tmp_x][tmp_y + 1] = 0; arr = ft_dfs(arr,tmp_x,tmp_y+1); } else if (arr[tmp_x + 1][tmp_y] == 1) { arr[tmp_x + 1][tmp_y] = 0; arr = ft_dfs(arr,tmp_x+1,tmp_y); } else break; } return arr; } }
bamgoesn
2년 전
0
반례입니다.
1 2 3 5 0 0 0 1 0 2 1 0 1 1 정답: 1 출력: 2
댓글을 작성하려면
로그인
해야 합니다.
ghkdwlgns612 2년 전
게시판 테스트케이스 대부분 통과하는데 25%에서 계속막히네요.. 도움부탁드려요 ㅠㅠㅠ