#P10011. [集训队互测 2023] 网格图最大流计数

[集训队互测 2023] 网格图最大流计数

Problem Description

Given n,m,kn, m, k, two positive integer sequences a1...n,b1...ma_{1...n}, b_{1...m}, and a k×kk \times k 0101 matrix s1...k,1...ks_{1...k,1...k}.

Consider a directed graph G=(V,E)G=(V,E), where $V=\{S,T\}\cup(\{0,1\}\times ([1,k]\cap\mathbb{Z})^2)$, and E=E1E2E3E=E_1\cup E_2\cup E_3 consists of three parts:

  • $E_1=\{(S,(0,1,a_i)) \mid 1\le i\le n\}\cup\{((1,k,b_i),T)\mid 1\le i\le m\}$
  • $E_2=\{((1,i,j),(0,i+1,j))\mid1\le i<k,1\le j\le k\}\cup \{(1,i,j),(0,i,j+1))\mid1\le i\le k,1\le j<k\}$
  • $E_3=\{((0,i,j),(1,i,j))\mid 1\le i,j\le k,s_{i,j}=1\}$

Simply put, you can think of each cell (i,j)(i,j), 1i,jk1\le i,j\le k, as being split into an in-node (0,i,j)(0,i,j) and an out-node (1,i,j)(1,i,j). E1E_1 describes the edges between S,TS, T and these nodes, determined by a,ba, b. E2E_2 describes edges from the out-node of each cell to the in-node of the cell above it and the cell to its right. E3E_3 describes edges from the in-node to the out-node within each cell, determined by ss.

Now treat GG as a flow network where every edge has capacity 11. You need to find the maximum flow from source SS to sink TT, and the number of maximum flows (two flows are considered different if and only if there exists an edge whose flow value differs between the two flows).

Input Format

The first line contains three positive integers n,m,kn, m, k.

The second line contains nn positive integers 1a1<a2<...<ank1\le a_1<a_2<...<a_n\le k.

The third line contains mm positive integers 1b1<b2<...<bmk1\le b_1<b_2<...<b_m\le k.

Then follow kk lines, each a binary string of length kk, representing the matrix ss.

Output Format

Output one line with two non-negative integers, representing the maximum flow and the number of maximum flows, respectively. The latter should be taken modulo 109+710^9+7.

Hint

The sample is provided in the attached file.

For all testdata, 1n,mk4001\le n,m\le k\le400.

Subtask ID nn\le kk\le Special Property Subtask Score
11 77 None 55
22 1818
33 1010 400400 1010
44 100100 2525
55 400400 n=mn=m and the maximum flow is nn 1010
66 The maximum flow is nn 2525
77 None 2020

Translated by ChatGPT 5