RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0203 파일 입출력

Bessie's Dream

Gold II 골드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

After eating too much fruit in Farmer John's kitchen, Bessie the cow is getting some very
strange dreams! In her most recent dream, she is trapped in a maze in the shape
of an \(N \times M\) grid of tiles (\(1 \le N, M \le 1,000\)). She starts on the
top-left tile and wants to get to the bottom-right tile. When she is standing on
a tile, she can potentially move to the adjacent tiles in any of the four
cardinal directions.

But wait! Each tile has a color, and each color has a different property!
Bessie's head hurts just thinking about it:

  • If a tile is red, then it is impassable.
  • If a tile is pink, then it can be walked on normally.
  • If a tile is orange, then it can be walked on normally, but will make Bessie smell like oranges.
  • If a tile is blue, then it contains piranhas that will only let Bessie pass if she smells like oranges.
  • If a tile is purple, then Bessie will slide to the next tile in that direction (unless she is unable to cross it). If this tile is also a purple tile, then Bessie will continue to slide until she lands on a non-purple tile or hits an impassable tile. Sliding through a tile counts as a move. Purple tiles will also remove Bessie's smell.

(If you're confused about purple tiles, the example will illustrate their use.)

Please help Bessie get from the top-left to the bottom-right in as few moves as
possible.

Problem credits: Nathan Pinsker, inspired by the game "Undertale"

제약

Problem credits: Nathan Pinsker, inspired by the game "Undertale".

입력 형식

The first line has two integers \(N\) and \(M\), representing the number of rows and
columns of the maze.

The next \(N\) lines have \(M\) integers each, representing the maze:

  • The integer '0' is a red tile
  • The integer '1' is a pink tile
  • The integer '2' is an orange tile
  • The integer '3' is a blue tile
  • The integer '4' is a purple tile

The top-left and bottom-right integers will always be '1'.

출력 형식

A single integer, representing the minimum number of moves Bessie must use to
cross the maze, or -1 if it is impossible to do so.

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 dream.in
출력을 쓸 파일 dream.out
예제 1
입력
4 4
1 0 2 1
1 1 4 1
1 0 4 0
1 3 1 1
출력
10
설명

In this example, Bessie walks one square down and two squares to the right (and
then slides one more square to the right). She walks one square up, one square
left, and one square down (sliding two more squares down) and finishes by
walking one more square right. This is a total of 10 moves (DRRRULDDDR).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2015-2016 > December > Gold

태그

평가 및 의견

Bessie's Dream

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Bessie's Dream

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8