No.2159 Filling 4x4 array
Problem Statement
This problem is based on Filling 3x3 array, but differs from it in various respects.
You are given $8$ integers $h_1$, $h_2$, $h_3$, $h_4$, $w_1$, $w_2$, $w_3$, $w_4$. Consider writing $1$ positive integer in each cell of a $4\times4$ grid so that all of the following conditions are satisfied.
- For $i=1,2,3,4$, the sum of the numbers written in the $i$-th row from the top is $h_i$.
- For $j=1,2,3,4$, the sum of the numbers written in the $j$-th column from the left is $w_j$.
How many ways are there to write the numbers so that the conditions are satisfied? Since the answer can be very large, output it modulo $998244353$.
Input
$h_1\ h_2\ h_3\ h_4\ w_1\ w_2\ w_3\ w_4$
- $4 \leq h_1, h_2, h_3, h_4, w_1, w_2, w_3, w_4 \leq 10^{9}$
- All input values are integers.
Output
Output the number of ways to write the numbers so that the conditions are satisfied, modulo $998244353$.
Print a newline at the end.
Sample
Sample 1
Input
4 5 7 4 4 4 8 4
Output
1
The only way to write the numbers that satisfies the conditions is the following $1$ way. Therefore, output $1$.
Sample 2
Input
4 4 5 6 6 7 8 9
Output
0
Sample 3
Input
6 14 11 4 7 14 10 4
Output
120
Sample 4
Input
21 4 26 31 4 23 30 25
Output
30613
Sample 5
Input
999999999 999999999 999999999 999999999 1000000000 1000000000 999999998 999999998
Output
823817983
Output the answer modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
hotman78
Nachia