#P15797. 【MX-J28-T4】「Cfz Round 8」Color Problem

    ID: 17696 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>动态规划 DPO2优化梦熊比赛

【MX-J28-T4】「Cfz Round 8」Color Problem

Problem Description

Given a 3×n3 \times n grid. A coloring scheme is defined to be valid if and only if:

  • In each column, exactly one cell is colored.
  • The colored cells in two adjacent columns are different.

For each cell (i,j)(i,j), there is a parameter si,js_{i,j}:

  • If si,j=0s_{i,j}=\texttt{0}, it means this cell must not be colored.
  • If si,j=1s_{i,j}=\texttt 1, it means this cell must be colored.
  • If si,j=?s_{i,j}=\texttt ?, it means this cell may be colored or not colored.

You need to compute the sum, over all valid coloring schemes, of the maximum connected component area consisting of uncolored cells. Since the answer may be very large, output it modulo 998,244,353998,244,353.

Input Format

This problem contains multiple test cases.

The first line of input contains two non-negative integers c,tc,t, representing the test point ID and the number of test cases, respectively. c=0c=0 means this test point is the sample.

Then the test cases follow. For each test case:

  • The first line contains a positive integer nn.
  • The next three lines: the ii-th line contains a string of length nn, si,1,…,si,ns_{i,1},\dots,s_{i,n}.

Output Format

For each test case:

  • Output one line containing a non-negative integer, which is the sum of the maximum connected component area of uncolored cells over all valid coloring schemes, modulo 998,244,353998,244,353.
0 3
1
?
?
?
2
?0
?1
?0
2
??
??
??
5
6
20

Hint

Sample 1 Explanation

This sample contains 33 test cases.

  • For test case 11:
    • If (1,1)(1,1) is colored, then the maximum connected component area of uncolored cells is 22.
    • If (2,1)(2,1) is colored, then the maximum connected component area of uncolored cells is 11.
    • If (3,1)(3,1) is colored, then the maximum connected component area of uncolored cells is 22.
    • The total over all schemes is (2+1+2) mod 998,244,353=5(2 + 1 + 2) \bmod 998,244,353 = 5.
  • For test case 22:
    • If (1,1)(1,1) is colored, then the maximum connected component area of uncolored cells is 33.
    • If (3,1)(3,1) is colored, then the maximum connected component area of uncolored cells is 33.
    • Note that the case where (2,1)\boldsymbol{(2,1)} is colored is not a valid scheme, because a valid coloring scheme must satisfy that the colored cells in adjacent columns are different.
    • The total over all schemes is (3+3) mod 998,244,353=6(3 + 3) \bmod 998,244,353 = 6.

Constraints

For all testdata:

  • 1≤t≤51 \le t \le 5;
  • 1≤n≤3001 \le n \le 300;
  • For all 1≤i≤31 \le i \le 3 and 1≤j≤n1 \le j \le n, si,j∈{0,1,?}s_{i,j} \in \{\texttt 0,\texttt 1 ,\texttt ?\}.

::cute-table{tuack}

Test Point ID n≤n \le Special Property
11 55 None
22 1010 ^
33 1515
44 2020
55 3030
66 4040
77 6060
88 8080
99 100100 A
1010 ^ B
1111 C
1212 None
1313 200200 A
1414 ^ B
1515 C
1616 None
1717 300300 A
1818 ^ B
1919 C
2020 None
  • Special Property A: For all 1≤i≤31 \le i \le 3 and 1≤j≤n1 \le j \le n, it is guaranteed that si,j≠?s_{i,j} \ne \texttt ?.
  • Special Property B: For all 1≤i≤n1 \le i \le n, it is guaranteed that s1,i=0s_{1,i} = \texttt 0.
  • Special Property C: For all 1≤i≤31 \le i \le 3 and 1≤j≤n1 \le j \le n, if (i+j) mod 2=0(i+j) \bmod 2 = 0, then si,j=0s_{i,j} = 0.

Translated by ChatGPT 5