회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
예제는 제대로 동작하는데, 뭐가 문제인지 잘 모르겠습니다.
2178번 - 미로 탐색
typhoon620620
2년 전
0
예제는 제대로 동작하는데, 뭐가 문제인지 잘 모르겠습니다.
#include <stdio.h> #include <limits.h> #include <stdbool.h> #define CAPACITY 100 // ** Global variable. char diffx[] = { -1, 0, 1, 0 }; char diffy[] = { 0, -1, 0, 1 }; int shortestTime = INT_MAX; // ** Function signature. void findTheShortestPath(bool board[CAPACITY][CAPACITY], short n, short m, short x, short y, short targetX, short targetY, int time); // ** Main method int main(void) { short n = 0, m = 0; scanf("%hd%hd", &n, &m); rewind(stdin); bool board[CAPACITY][CAPACITY] = { false, }; char element = 0; for (int row = 0; row < n; row++) { for (int col = 0; col < m; col++) { scanf("%c", &element); if (element-48 == 1) board[row][col] = true; } rewind(stdin); } findTheShortestPath(board, n, m, 0, 0, m - 1, n - 1, 1); printf("%d", shortestTime); return 0; } // ** DFS void findTheShortestPath(bool board[CAPACITY][CAPACITY], short n, short m, short x, short y, short targetX, short targetY, int time) { if (x < 0 || x >= m || y < 0 || y >= n) return; else if (!board[y][x] || time > shortestTime) return; else if (x == targetX && y == targetY) { shortestTime = time; return; } board[y][x] = false; for (int i = 0; i < 4; i++) findTheShortestPath(board, n, m, x + diffx[i], y + diffy[i], targetX, targetY, time + 1); board[y][x] = true; }
댓글을 작성하려면
로그인
해야 합니다.
typhoon620620 2년 전
예제는 제대로 동작하는데, 뭐가 문제인지 잘 모르겠습니다.