P26592 [AtCoder] Filling in the Grid
NOI
题目描述

Problem Description

You are given an 18-row by 6-column grid. Each cell contains either 0, 1, or ?, and the cell at the i-th row and j-th column contains $ s_{i,j} $.

For all cells containing ?, how many ways are there to replace the ? with either 0 or 1 such that the grid satisfies the following condition?

Condition: Each cell's number is equal to the median of the five numbers written in the cell and its adjacent cells (up, down, left, right). (Treat cells outside the grid as containing 0.)

Input Format

The input is given from the standard input in the following format:

$ s_{1,1} $ $\cdots$ $ s_{1,6} $ $\vdots$ $ s_{18,1} $ $\cdots$ $ s_{18,6} $

Output Format

Output the number of ways to replace the ?s such that the grid satisfies the condition described in the problem.

Sample Input and Output

Sample Input #1

??0000
??0000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000

Sample Output #1

2

Sample Input #2

???000
???000
???000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000
000000

Sample Output #2

16

Sample Input #3

?01000
1101?1
100111
1?11??
???00?
00011?
1?1??1
000101
100?11
1010??
?101??
?1??10
????10
?1??0?
1?1???
110?1?
0000?0
001?10

Sample Output #3

0

Sample Input #4

??????
??????
??????
??????
??????
??????
??????
??????
??????
??????
??????
??????
??????
??????
??????
??????
??????
??????

Sample Output #4

243882696958399859

Notes/Hints

Note

Discussion of this problem is prohibited until 2020/11/8 18:00 JST. Disclosure of information about which problems were solved may result in claims for compensation. It is okay to publish the total score and certification level after the exam, but please refrain from disseminating information about which specific problems were solved.

Constraints

  • $ s_{i,j} $ is either 0, 1, or ?

Sample Explanation 1

  • The condition in the problem is satisfied only when all ? cells are filled with 0 or all ? cells are filled with 1.

Sample Explanation 3

  • There is no way to fill the ? cells that satisfies the condition.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
??0000 ??0000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
样例输出
2