회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
13460 구슬탈출2
13460번 - 구슬 탈출 2
karl0905
3년 전
0
주어진 테스트케이스는 잘 돌아가는데 뭐가 문제인지 궁금합니다 ㅠㅠ
#pragma warning(disable: 4996) #include<iostream> #include<queue> #define MAX_LEN 10 using namespace std; int n, m; char map[MAX_LEN + 1][MAX_LEN + 1]; const int dx[] = { 0,0,1,-1 }; const int dy[] = { -1,1,0,0 }; struct Pos { int x; int y; }; struct queue_ele { Pos red; Pos blue; int count; }; Pos red, blue, hole; void input() { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf(" %c", &map[i][j]); if (map[i][j] == 'R') { red.x = i; red.y = j; map[i][j] = '.'; } else if (map[i][j] == 'B') { blue.x = i; blue.y = j; map[i][j] = '.'; } else if (map[i][j] == 'O') { hole.x = i; hole.y = j; } } } } bool red_first(Pos red, Pos blue, int dir) { // 상 if (dir == 0) { if (red.y == blue.y && red.x > blue.x) return false; } // 하 else if (dir == 1) { if (red.y == blue.y && blue.x > red.x) return false; } // 우 else if (dir == 2) { if (red.x == blue.x && blue.y > red.y) return false; } // 좌 else if (dir == 3) { if (red.x == blue.x && red.y > blue.y) return false; } return true; } bool go(Pos& pos, int dir, bool is_red) { char ch = is_red == true ? 'R' : 'B'; while (true) { int cx = pos.x + dx[dir]; int cy = pos.y + dy[dir]; if (map[cx][cy] == 'O') { map[pos.x][pos.y] = '.'; return true; } //return true; else if (map[cx][cy] != '.') break; map[pos.x][pos.y] = '.'; map[cx][cy] = ch; pos.x = cx; pos.y = cy; } return false; } int main() { scanf(" %d %d", &n, &m); input(); queue<queue_ele> q; q.push({ red, blue, 0 }); while (!q.empty()) { queue_ele patch = q.front(); q.pop(); if (patch.count >= 10) continue; for (int i = 0; i < 4; i++) { Pos ori_red = patch.red; Pos ori_blue = patch.blue; map[red.x][red.y] = 'R'; map[blue.x][blue.y] = 'B'; bool check_red, check_blue; if (red_first(patch.red, patch.blue, i)) { check_red = go(red, i, true); check_blue = go(blue, i, false); } else { check_blue = go(blue, i, false); check_red = go(red, i, true); } if (!check_blue) { if (check_red) { printf("%d", patch.count + 1); return 0; } else { if (ori_red.x != red.x || ori_red.y != red.y || ori_blue.x != blue.x || ori_blue.y != blue.y) { q.push({ red, blue, patch.count + 1 }); } } } map[red.x][red.y] = '.'; map[blue.x][blue.y] = '.'; red = ori_red; blue = ori_blue; } } printf("-1"); return 0; }
tony9402
3년 전
1
반례 드립니다.
10 7 ####### ##..#.# ###.### #####.# #.###.# ##..#.# #O....# ####..# #...RB# ####### answer : 2 10 5 ##### #..R# #..B# #...# ##..# ##.## #O.## ##### ##..# ##### answer : 6 7 9 ######### #####..## ##..#..## #...#O### ###.....# #..#R.B.# ######### answer : -1 7 7 ####### #...#.# #..#.## #.#...# #.B.#R# ##O..## ####### answer : 4 6 9 ######### ##O..#.## ###.#..## #....#..# #B#R##.## ######### answer : 2 5 10 ########## #.#.O..#.# #####R.#B# ####.....# ########## answer : 2 7 5 ##### #..R# #B.## #.#.# #..O# #...# ##### answer : 3 6 10 ########## #.##..R..# ##.O.###.# ####.##.B# ##.##.#### ########## answer : 6 7 5 ##### #OB.# #..## #...# #.R.# #...# ##### answer : -1
댓글을 작성하려면
로그인
해야 합니다.
karl0905 3년 전
주어진 테스트케이스는 잘 돌아가는데 뭐가 문제인지 궁금합니다 ㅠㅠ