Logo
(追記) (追記ここまで)

32504번 - Light Up 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB58434177.358%

문제

Light Up is a pencil puzzle. Your job will not be to play Light Up, but simply to judge whether a player’s solution is correct.

The game is played on a square grid. Some of the cells are blocked, and some of the blocked cells have a number from 0ドル$ to 4ドル$. The player must place light bulbs in open cells. Each light bulb can light all of the open cells above, below, left, and right (but not diagonally) until the light reaches the edge of the grid or a blocked cell. The player must place light bulbs so that:

  • Every open cell is lit.
  • No two light bulbs can shine on each other.
  • Any blocked cell with a number in it must have exactly that number of light bulbs immediately adjacent above, below, left, or right. Diagonals do not count.

The following is an example grid with its solution:

Given a grid with light bulbs placed, determine whether it is, in fact, a solution. Note that if a grid has no open cells, and does not violate any other constraints, it is trivially solved.

입력

The first line of input contains a single integer $n$ (1ドル≤n≤30$), which is the number of rows and columns in the grid.

Each of the next $n$ lines contains exactly $n$ characters from the set {‘.’,‘X’,‘?’,‘0’,‘1’,‘2’,‘3’,‘4’}. This is the grid, with ‘.’ representing an open cell, ‘X’ representing a blocked cell, ‘?’ representing a light bulb, and the numbers ‘0’,‘1’,‘2’,‘3’,‘4’ representing a blocked cell with a constraint on the number of adjacent light bulbs.

출력

Output a single integer, which is 1ドル$ if the input is a valid solution, and 0ドル$ otherwise.

제한

예제 입력 1

7
.?.0..?
..X.1?.
.X.?.2.
.....?.
?3?..2.
.?3.X?.
..?X?..

예제 출력 1

1

예제 입력 2

7
.?.0..?
..X.1?.
.X...2.
.....?.
?3?..2.
.?3.X?.
..?X?..

예제 출력 2

0

힌트

출처

ICPC > Regionals > North America > North America Qualification Contest > ICPC North America Qualifier 2024 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /