회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
8%에서 막혔습니다. 모든 반례 다 넣어봄..(C#)
13460번 - 구슬 탈출 2
skfro2013
1년 전
0
8%에서 막히네요... ㅠㅠㅠㅠㅠ
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace BackJ { class Program { static void Main(string[] args) { StreamReader sr = new StreamReader(Console.OpenStandardInput()); StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); int[] inputs = Array.ConvertAll(sr.ReadLine().Split(), int.Parse); int Y = inputs[0]; int X = inputs[1]; List<List<char>> board = new List<List<char>>(); for (int i = 0; i < Y; i++) board.Add(sr.ReadLine().ToList()); Pos red = null; Pos blue = null; Pos hole = null; for (int y = 0; y < Y; y++) { for (int x = 0; x < X; x++) { if (board[y][x] == 'R') { red = new Pos(y, x); } else if (board[y][x] == 'B') { blue = new Pos(y, x); } else if (board[y][x] == 'O') hole = new Pos(y, x); } } bool[,,,] visited = new bool[Y, X, Y, X]; int[] dx = new int[4] { 1, -1, 0, 0 }; int[] dy = new int[4] { 0, 0, 1, -1 }; int result = -1; // BFS 시작. Queue<TPos> q = new Queue<TPos>(); q.Enqueue(new TPos(red, blue, 0)); visited[red.Y, red.X, blue.Y, blue.X] = true; while (q.Count > 0) { TPos current = q.Dequeue(); Pos RED = current.RedPos; Pos BLUE = current.BluePos; int nextCount = current.Count + 1; if (nextCount >= 10) continue; for (int direction = 0; direction < 4; direction++) { Tuple<int, int, int, bool> redMove = Move(RED.Y, RED.X, direction); int nextRedY = redMove.Item1; int nextRedX = redMove.Item2; int moveRed = redMove.Item3; bool redHole = redMove.Item4; Tuple<int, int, int, bool> blueMove = Move(BLUE.Y, BLUE.X, direction); int nextBlueY = blueMove.Item1; int nextBlueX = blueMove.Item2; int moveBlue = blueMove.Item3; bool blueHole = blueMove.Item4; if (blueHole == true) continue; if (redHole == true) { result = nextCount; goto end; } if (nextRedY == nextBlueY && nextRedX == nextBlueX) { if (moveRed > moveBlue) { nextRedY -= dy[direction]; nextRedX -= dx[direction]; } else if (moveRed < moveBlue) { nextBlueY -= dy[direction]; nextBlueX -= dx[direction]; } } if (visited[nextRedY, nextRedX, nextBlueY, nextBlueX] == false) { visited[nextRedY, nextRedX, nextBlueY, nextBlueX] = true; q.Enqueue(new TPos(new Pos(nextRedY, nextRedX), new Pos(nextBlueY, nextBlueX), nextCount)); } } } Tuple<int, int, int, bool> Move(int y, int x, int d) { int count = 1; while (true) { if (board[y + dy[d]][x + dx[d]] == 'O') return new Tuple<int, int, int, bool>(y, x, count, true); else if (board[y + dy[d]][x + dx[d]] == '#') return new Tuple<int, int, int, bool>(y, x, count, false); y += dy[d]; x += dx[d]; count++; } } end: sw.WriteLine(result); sw.Flush(); sw.Close(); sr.Close(); } } public class Pos { public int Y; public int X; public Pos(int y, int x) { Y = y; X = x; } } public class TPos { public Pos RedPos; public Pos BluePos; public int Count = 0; public TPos(Pos redPos, Pos bluePos, int count) { RedPos = redPos; BluePos = bluePos; Count = count; } } }
skfro2013
1년 전
0
하.. 10번 이하를 잘 못 이해했습니다. 해결됐네요 ㅠㅠ
댓글을 작성하려면
로그인
해야 합니다.
skfro2013 1년 전
8%에서 막히네요... ㅠㅠㅠㅠㅠ