회원가입
로그인
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
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
예외좀 찾아주세요 ㅠㅠ
7576번 - 토마토
ysoo14
5년 전
0
어떤 부분이 잘못됐는지 모르겠습니다.
#include<iostream> #include<cstring> using namespace std; int map[1001][1001]; int check[1001][1001]; int que_x[1002]; int que_y[1002]; int top = 0; int tail = 0; int total = 0; int p = 0; int dir_x[4] = {0,1,0,-1}; int dir_y[4] = {1,0,-1,0}; int m,n; void bfs(){ while(top > tail){ int x = que_x[++tail]; int y = que_y[tail]; for(int i = 0; i < 4; i++){ int next_x = x + dir_x[i]; int next_y = y + dir_y[i]; if(next_x > - 1 && next_x < m && next_y > - 1 && next_y < n){ if(map[next_y][next_x] == 0 && check[next_y][next_x] == 0){ check[next_y][next_x] = 1; map[next_y][next_x] = map[y][x]+1; que_x[++top] = next_x; que_y[top] = next_y; ++p; } } } } } int main(){ int fail = -1; int no = 0; cin >> m >> n; total = n * m; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin >> map[i][j]; if(map[i][j] == 1){ que_x[++top] = j; que_y[top] = i; ++p; } if(map[i][j] == -1){ --total; } } } bfs(); if(total != p) cout << fail << endl; else if(total == 0) cout << no << endl; else cout << map[que_y[top]][que_x[top]] - 1 << endl; }
k5nen
5년 전
1
큐의 길이가 너무 짧습니다. 길이를 늘리니바로 통과되네요.
ysoo14
5년 전
0
감사합니다~~
댓글을 작성하려면
로그인
해야 합니다.
ysoo14 5년 전
어떤 부분이 잘못됐는지 모르겠습니다.