RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 IOIF004 ⇄ 인터랙티브

Mecho

설명

Mecho the bear is on an \(N \times N\) grid of cells: grass G, trees T (impassable), bee hives H, Mecho's start M, and his home cave D. Bees spread from every hive through grass, advancing exactly one cell (in the 4 directions) each minute; bees never enter the cave D, trees, or hives. Mecho walks through grass (and into D) up to \(S\) steps per minute.

Mecho first eats honey at M for a whole number of minutes, during which the bees keep spreading, then walks home. Timing rule: if he eats \(t\) minutes, then after taking \(s\) walking steps the current minute is \(t + \lfloor s / S \rfloor\); he may occupy a cell only if the bees reach it strictly later than that minute.

Output the maximum \(t\) for which Mecho can still reach the cave safely, or -1 if he cannot even by leaving immediately.

Note. This is an adaptation of an IOI function-implementation task to an interactive stdin/stdout problem. The test data is RiseOJ-generated (self-validated against an independent brute force), not the official IOI data.

Interaction / I/O protocol

Input. Line 1: \(N\) and \(S\). The next \(N\) lines each contain a string of \(N\) characters from GTHMD describing the grid.

Output. Print one integer: the maximum eating time, or -1.

Example.

MGGG
GGGG
GGGG
HGGD

with S=1: the answer is the largest number of minutes Mecho may wait and still out-run the bees to D.

제약
  • \(1 \le N \le 800\)
  • \(1 \le S \le 1000\)
  • Exactly one M and one D; at least one H.
입력 형식

Line 1: \(N\) and \(S\). The next \(N\) lines each contain a string of \(N\) characters from GTHMD describing the grid.

출력 형식

Print one integer: the maximum eating time, or -1.

인터랙티브 문제
프로그램이 고정된 입력을 읽는 대신 표준 입출력으로 채점기와 메시지를 주고받습니다. 한 줄을 출력할 때마다 표준 출력을 flush하고(예: cout에 endl / print(..., flush=True) / System.out.flush()), 채점기의 응답을 읽으세요. 파일을 읽거나 쓰면 안 됩니다.
문제 정보

rip 작성

출처 IOI 2009

평가 및 의견

Mecho

개요
출제자 난이도 Platinum V 플래티넘 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Mecho

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