A12913 | Filling the Grid
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Suppose there is a $h \times w$ grid consisting of empty or full cells. Let's make some definitions:
- $r_{i}$ is the number of consecutive full cells connected to the left side in the $i$ -th row ( $1 \le i \le h$ ). In particular, $r_i=0$ if the leftmost cell of the $i$ -th row is empty.
- $c_{j}$ is the number of consecutive full cells connected to the top end in the $j$ -th column ( $1 \le j \le w$ ). In particular, $c_j=0$ if the topmost cell of the $j$ -th column is empty.
In other words, the $i$ -th row starts exactly with $r_i$ full cells. Similarly, the $j$ -th column starts exactly with $c_j$ full cells.
These are the $r$ and $c$ values of some $3 \times 4$ grid. Black cells are full and white cells are empty.You have values of $r$ and $c$ . Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $r$ and $c$ . Since the answer can be very large, find the answer modulo $1000000007\,(10^{9} + 7)$ . In other words, find the remainder after division of the answer by $1000000007\,(10^{9} + 7)$ .
- $r_{i}$ is the number of consecutive full cells connected to the left side in the $i$ -th row ( $1 \le i \le h$ ). In particular, $r_i=0$ if the leftmost cell of the $i$ -th row is empty.
- $c_{j}$ is the number of consecutive full cells connected to the top end in the $j$ -th column ( $1 \le j \le w$ ). In particular, $c_j=0$ if the topmost cell of the $j$ -th column is empty.
In other words, the $i$ -th row starts exactly with $r_i$ full cells. Similarly, the $j$ -th column starts exactly with $c_j$ full cells.
These are the $r$ and $c$ values of some $3 \times 4$ grid. Black cells are full and white cells are empty.You have values of $r$ and $c$ . Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $r$ and $c$ . Since the answer can be very large, find the answer modulo $1000000007\,(10^{9} + 7)$ . In other words, find the remainder after division of the answer by $1000000007\,(10^{9} + 7)$ .
输入格式
The first line contains two integers $h$ and $w$ ( $1 \le h, w \le 10^{3}$ ) — the height and width of the grid.
The second line contains $h$ integers $r_{1}, r_{2}, \ldots, r_{h}$ ( $0 \le r_{i} \le w$ ) — the values of $r$ .
The third line contains $w$ integers $c_{1}, c_{2}, \ldots, c_{w}$ ( $0 \le c_{j} \le h$ ) — the values of $c$ .
The second line contains $h$ integers $r_{1}, r_{2}, \ldots, r_{h}$ ( $0 \le r_{i} \le w$ ) — the values of $r$ .
The third line contains $w$ integers $c_{1}, c_{2}, \ldots, c_{w}$ ( $0 \le c_{j} \le h$ ) — the values of $c$ .
输出格式
Print the answer modulo $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 $r$ , $c$ values.
In the third example, make sure to print answer modulo $(10^9 + 7)$ .
In the second example, it's impossible to make a grid to satisfy such $r$ , $c$ values.
In the third example, make sure to print answer modulo $(10^9 + 7)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted