#abc215h. H - Cabbage Master

H - Cabbage Master

Score : 600600 points

问题描述

Takahashi 是一位卷心菜农,他种植了 NN 个品牌的卷心菜,分别称为品牌 11 到品牌 NN。他有 AiA_i 个品牌 ii 的卷心菜 (1iN)(1 \leq i \leq N)。在这里,所有卷心菜都是可区分的

他有 MM 个客户,称为公司 11 到公司 MM。公司 jj (1jM)(1 \leq j \leq M) 订购了 BjB_j 个卷心菜。

不同的公司接受不同品牌的卷心菜。对于每一对 i,ji, j (1iN,1jM)(1 \leq i \leq N, 1 \leq j \leq M)

  • 如果 ci,j=1c_{i, j} = 1,品牌 ii 的卷心菜可以被运送到公司 jj
  • 如果 ci,j=0c_{i, j} = 0,品牌 ii 的卷心菜不能被运送到公司 jj

如果 Takahashi 成功地决定将卷心菜运送到何处,使得每个公司 jj (1jM)(1 \leq j \leq M) 至少收到 BjB_j 或更多的卷心菜,则称他为“卷心菜大师”。

Snuke 决定选择并吃掉零个或多个卷心菜,以便无论 Takahashi 将卷心菜运送到哪里,都无法获得“卷心菜大师”的称号。他不太喜欢卷心菜,因此他会选择吃掉实现这一目标所需的 最小 数量的卷心菜。

打印出 Snuke 将要吃掉的卷心菜数量,以及 Snuke 选择吃卷心菜的方式数,结果对 998244353998244353 取模。两种选择卷心菜的方式被认为是不同的,当存在一个在一种方式中被吃掉而在另一种方式中未被吃掉的卷心菜时。请注意,即使两个卷心菜是同一品牌,它们也是 可区分的

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi, a cabbage farmer, has grown NN brands of cabbages, called Brand 11 through Brand NN. He has AiA_i heads of cabbage of Brand ii (1iN)(1 \leq i \leq N). Here, all heads of cabbages are distinguishable.
He has MM clients called Company 11 through Company MM. Company jj (1jM)(1 \leq j \leq M) has ordered BjB_j heads of cabbages.
Different companies accept different brands of cabbages. For each pair i,ji, j (1iN,1jM)(1 \leq i \leq N, 1 \leq j \leq M),

  • if ci,j=1c_{i, j} = 1, cabbage of Brand ii can be shipped to Company jj;
  • if ci,j=0c_{i, j} = 0, cabbage of Brand ii cannot be shipped to Company jj.

Takahashi will be called a Cabbage Master if he succeeds in deciding where to ship the heads of cabbages so that BjB_j or more heads of cabbages will be shipped to every company jj (1jM)(1 \leq j \leq M).

Snuke has decided to choose and eat zero or more heads of cabbages so that Takahashi cannot get the title of Cabbage Master, regardless of where to ship his cabbages. He does not like cabbage very much, so he will choose to eat the minimum number of heads of cabbages needed to achieve his objective.

Print the number of heads of cabbages Snuke will eat, and the number of ways, modulo 998244353998244353, for Snuke to choose heads of cabbages to eat. Two ways to choose heads of cabbages are considered different when there is a head of cabbage that is eaten in one way but not in the other. Here, remember that any two heads of cabbages are distinguishable even if they are of the same brand.

Constraints

  • 1N201 \leq N \leq 20
  • 1M1041 \leq M \leq 10^4
  • 1Ai1051 \leq A_i \leq 10^5
  • 1Bj1051 \leq B_j \leq 10^5
  • ci,j{0,1}c_{i, j} \in \lbrace 0, 1 \rbrace
  • For every 1jM1 \leq j \leq M, there exists 1iN1 \leq i \leq N such that ci,j=1c_{i, j} = 1.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BMB_M

c1,1c_{1, 1} c1,2c_{1, 2} \ldots c1,Mc_{1, M}

c2,1c_{2, 1} c2,2c_{2, 2} \ldots c2,Mc_{2, M}

\vdots

cN,1c_{N, 1} cN,2c_{N, 2} \ldots cN,Mc_{N, M}

Output

Print XX, the number of heads of cabbages Snuke will eat, and YY, the number of ways for Snuke to choose heads of cabbages to eat, modulo 998244353998244353, in this order, with a space in between.

XX YY

Sample Input 1

3 2
2 2 5
3 4
1 0
1 1
0 1

Sample Output 1

2 6

Snuke will eat two heads of cabbages to prevent Takahashi from becoming a Cabbage Master. There are six such ways to choose heads of cabbages to eat, as shown below, where (i,j)(i, j) denotes the jj-th head of cabbage of Brand ii.

  • (1,1),(1,2)(1, 1), (1, 2)
  • (1,1),(2,1)(1, 1), (2, 1)
  • (1,1),(2,2)(1, 1), (2, 2)
  • (1,2),(2,1)(1, 2), (2, 1)
  • (1,2),(2,2)(1, 2), (2, 2)
  • (2,1),(2,2)(2, 1), (2, 2)

Sample Input 2

1 1
3
4
1

Sample Output 2

0 1

It is possible that Takahashi is unable to become a Cabbage Master even if Snuke eats no cabbage. Then, Snuke will eat zero heads of cabbages, and there is just one way for him to choose heads of cabbages to eat: do not eat anything.

Sample Input 3

1 3
100
30 30 30
1 1 1

Sample Output 3

11 892328666

For the number of ways for Snuke to choose heads of cabbages to eat, be sure to print it modulo 998244353998244353.

update @ 2024/3/10 09:34:16