회원가입
로그인
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
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
어디가 틀렸는지 모르겠어요
18224번 - 미로에 갇힌 건우
smucs13
3년 전
0
예제는 맞는데
반례도 없구 뭐가 틀렸는지 모르겠어요
푸신분들 도와주세요
// https://www.acmicpc.net/problem/18224 #include<bits/stdc++.h> using namespace std; typedef struct { int x, y, cnt, day, th; }Info; const int MAX = 500; int N, M; int MAP[MAX][MAX]; bool visited[MAX][MAX][11][2]; // 0이면 낮, 1이면 밤 int dx[] = { 0,0,1,-1 }; int dy[] = { 1,-1,0,0 }; void bfs() { queue<Info> q; q.push({ 0,0,0,0,1 }); visited[0][0][0][0] = true; // x,y,cnt,day while (!q.empty()) { int size = q.size(); for (int k = 0; k < size; k++) { int x = q.front().x; int y = q.front().y; int cnt = q.front().cnt; int day = q.front().day; int th = q.front().th; q.pop(); if (x == N - 1 && y == N - 1) { cout << th << ' '; if (day == 0) cout << "sun" << '\n'; else cout << "moon" << '\n'; return; } for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; int ncnt = (cnt + 1) % M; int nday = day; int nth = th; if (ncnt == 0) { // m번 만큼 움직였을 떄 if (day == 0) nday = 1; // 낮이었으면 밤으로 else if (day == 1) { // 밤이었으면 낮으로, 번째날 1일 더해주기 nday = 0; nth++; } } if (nx < 0 || nx >= N || ny < 0 || ny >= N || visited[nx][ny][ncnt][nday]) continue; if (MAP[nx][ny] == 0) { q.push({ nx,ny,ncnt, nday, nth }); visited[nx][ny][ncnt][nday] = true; } else if (MAP[nx][ny] == 1) { if (day == 1) { // 밤에만 벽을 넘을 수 있음 int nnx = nx, nny = ny; while (true) { nnx += dx[i]; nny += dy[i]; if (nnx < 0 || nnx >= N || nny < 0 || nny >= N) break; if (MAP[nnx][nny] == 0 && visited[nnx][nny][ncnt][nday] == false) { q.push({ nnx,nny,ncnt,nday,nth }); visited[nnx][nny][ncnt][nday] = true; break; } } } } } } } cout << -1 << '\n'; return; } void solve() { bfs(); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> N >> M; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> MAP[i][j]; } } solve(); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
smucs13 3년 전
예제는 맞는데
반례도 없구 뭐가 틀렸는지 모르겠어요
푸신분들 도와주세요