회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
토마토 문제 질문입니다.
7576번 - 토마토
boffin
6년 전
0
결과로 틀렸습니다 라고 나오는데 뭘 놓친건지 모르겠습니다
도와주세요ㅠ
#include<stdio.h> typedef struct cass { int x; int y; }cass; int cas[1001][1001] = { 0 }; int dp[1001][1001] = { 0 }; int xque[1000021] = { 0 }; int yque[1000021] = { 0 }; int main() { int N, M; int gox[4] = { 1,-1,0,0 }; int goy[4] = { 0,0,1,-1 }; int front = 1, tail = 0; int but0 = 0, but1 = 0; cass cur, next; //printf("\n\n-----시작-----\n\n"); scanf("%d %d", &N, &M); for (int i = 1; i <= N; i++) for (int j = 1; j <= M; j++) scanf("%d", &cas[i][j]); //printf("\n\n-----받기완료-----\n\n"); for (int i = 1; i <= N; i++) for (int j = 1; j <= M; j++) { if (cas[i][j] == 1) { but1 = 1; xque[++tail] = j; yque[tail] = i; dp[i][j] = 0; } else but0 = 1; } //printf("\n\n-----큐입력완료-----\n\n"); cur.x = xque[1]; cur.y = yque[1]; if (but1 != 1)printf("-1"); else if (but0 != 1)printf("0"); else { while (1) { for (int i = 0; i < 4; i++) {//상하좌우에대한 다음 이동 값 next.x = cur.x + gox[i]; next.y = cur.y + goy[i]; if (next.x > 0 && next.x <= M&&next.y > 0 && next.y <= N) { if (cas[next.y][next.x] == 0) { xque[++tail] = next.x;//다음장소들을 큐에 넣음 yque[tail] = next.y; cas[next.y][next.x] = 1;//익었음 dp[next.y][next.x] = dp[cur.y][cur.x] + 1;//전단계의 일수+1 } } } cur.x = xque[++front];//상하좌우, 다 끝났으면 큐에있는 다음 토마토로이동 cur.y = yque[front]; if (front >= tail) { //printf("\n\n-----마침-----\n\n"); printf("%d", dp[yque[tail]][xque[tail]]);//마지막 break; } } } }
댓글을 작성하려면
로그인
해야 합니다.
boffin 6년 전
결과로 틀렸습니다 라고 나오는데 뭘 놓친건지 모르겠습니다
도와주세요ㅠ