Movatterモバイル変換


[0]ホーム

URL:


Logo

33419번 -Daisies on a Grid다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초2048 MB0000.000%

문제

You are given a grid consisting of $n$ rows and $m$ columns where each cell is a place for a magical daisy. Each daisy can have one of the three possible colors, represented by $0$, $1$, and $2$.

Each daisy gazes at its surrounding flowers and desires to transform into the appearance of other daisies. If at the start of some second, a daisy of color $c$ has at least one neighboring flower above, below, to the left, or to the right with color $c - 1$, then in the next second, this daisy will turn into color $c - 1$; otherwise, its color remains $c$ in the next second (we consider the colors modulo $3$).

Consider an initial arrangement of daisies on the grid. The arrangement isbeautiful if, after a finite number of seconds, all daisies become the same color.

It is easy to see that, for a beautiful daisy arrangement, each flower has an earliest second $t$ such that its color remains unchanged after second $t$. We call this second the flower'sstable second. We start counting from second $0$, so, if a flower never changes color, its stable second is $0$.

Now, some daisies are already placed in some cells of the grid, and the other cells are empty. How many ways are there to place daisies in the remaining cells so that the arrangement is beautiful? Also, for all these beautiful arrangements, what is the total sum of stable seconds for the daisy in the top left cell (the cell on the intersection of the first row and the first column)?

As both numbers may be very large, find them modulo $998\,244\,353$.

입력

The first line of the input contains two integers $n$ and $m$ ($2 \le n \le 5$, $2 \le m \le 50$).

Then the description of the initial state of the grid follows: the following $n$ lines contain $m$ integers each. The $j$-th integer in the $i$-th line, $a_{i,j} \in \{0, 1, 2, 3\}$, represents the state of the corresponding cell. Here, $a_{i,j} \in \{0, 1, 2\}$ indicates a daisy of the respective color, and $a_{i,j} = 3$ indicates that the cell contains no daisy.

출력

Print a line with two integers: the number of beautiful arrangements and the total sum of stable seconds for the daisies in the top left cell in those arrangements, both modulo $998\,244\,353$.

제한

예제 입력 1

2 21 03 2

예제 출력 1

1 2

예제 입력 2

5 53 3 3 3 22 3 3 3 11 3 3 3 33 3 3 3 33 3 3 3 3

예제 출력 2

50830224 170059345

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2024 > Day 2: CCPC Contest 1 D번

출처

대학교 대회

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


[8]ページ先頭

©2009-2025 Movatter.jp