CF1228B.Filling the Grid

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Suppose there is a h×wh \times w grid consisting of empty or full cells. Let's make some definitions:

  • rir_{i} is the number of consecutive full cells connected to the left side in the ii-th row (1≤i≤h1 \le i \le h). In particular, ri=0r_i=0 if the leftmost cell of the ii-th row is empty.
  • cjc_{j} is the number of consecutive full cells connected to the top end in the jj-th column (1≤j≤w1 \le j \le w). In particular, cj=0c_j=0 if the topmost cell of the jj-th column is empty.

In other words, the ii-th row starts exactly with rir_i full cells. Similarly, the jj-th column starts exactly with cjc_j full cells.

These are the rr and cc values of some 3×43 \times 4 grid. Black cells are full and white cells are empty.

You have values of rr and cc. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of rr and cc. Since the answer can be very large, find the answer modulo 1000000007 (109+7)1000000007\,(10^{9} + 7). In other words, find the remainder after division of the answer by 1000000007 (109+7)1000000007\,(10^{9} + 7).

假设有一个 h×wh \times w 的网格,每个格子为空或满。我们给出如下定义:

  • rir_{i} 表示第 ii 行(1≤i≤h1 \le i \le h)中与左边界相连的连续满格子的个数。特别地,若第 ii 行最左侧的格子为空,则 ri=0r_i = 0。
  • cjc_{j} 表示第 jj 列(1≤j≤w1 \le j \le w)中与上边界相连的连续满格子的个数。特别地,若第 jj 列最上方的格子为空,则 cj=0c_j = 0。

换言之,第 ii 行恰好以 rir_i 个满格子开头;第 jj 列恰好以 cjc_j 个满格子开头。

这是一个 3×43 \times 4 网格对应的 rr 和 cc 值示例。黑色格子为满格子,白色格子为空格子。

已知 rr 和 cc 的值,初始时所有格子均为空。求满足给定 rr 和 cc 值的填法总数。由于答案可能非常大,请对 1000000007 (109+7)1000000007\,(10^{9} + 7) 取模输出结果,即输出答案除以 1000000007 (109+7)1000000007\,(10^{9} + 7) 后的余数。

输入格式

The first line contains two integers hh and ww (1≤h,w≤1031 \le h, w \le 10^{3}) — the height and width of the grid.

The second line contains hh integers r1,r2,…,rhr_{1}, r_{2}, \ldots, r_{h} (0≤ri≤w0 \le r_{i} \le w) — the values of rr.

The third line contains ww integers c1,c2,…,cwc_{1}, c_{2}, \ldots, c_{w} (0≤cj≤h0 \le c_{j} \le h) — the values of cc.

第一行包含两个整数 hh 和 ww(1≤h,w≤1031 \le h, w \le 10^{3})——网格的高度和宽度。

第二行包含 hh 个整数 r1,r2,…,rhr_{1}, r_{2}, \ldots, r_{h}(0≤ri≤w0 \le r_{i} \le w)——rr 的值。

第三行包含 ww 个整数 c1,c2,…,cwc_{1}, c_{2}, \ldots, c_{w}(0≤cj≤h0 \le c_{j} \le h)——cc 的值。

输出格式

Print the answer modulo 1000000007 (109+7)1000000007\,(10^{9} + 7).

对 1000000007 (109+7)1000000007\,(10^{9} + 7) 取模后输出答案。

输入输出样例

  • 输入#1

    3 4
    0 3 1
    0 2 3 0

    输出#1

    2
  • 输入#2

    1 1
    0
    1

    输出#2

    0
  • 输入#3

    19 16
    16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12
    6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4

    输出#3

    797922655

说明/提示

In the first example, this is the other possible case.

In the second example, it's impossible to make a grid to satisfy such rr, cc values.

In the third example, make sure to print answer modulo (109+7)(10^9 + 7).

在第一个例子中,这是另一种可能的情况。

在第二个例子中,无法构造出满足给定 rr、cc 值的网格。

在第三个例子中,请确保输出答案对 (109+7)(10^9 + 7) 取模的结果。

输入解题思路,AI测评打分。不知道怎么写?

首页