#abc256c. C - Filling 3x3 array

C - Filling 3x3 array

Score : 300300 points

问题描述

给定六个整数:h1,h2,h3,w1,w2h_1, h_2, h_3, w_1, w_2w3w_3

考虑在一个 3×33 \times 3 的网格中,将每个格子填入一个 整数,使得满足以下所有条件:

  • 对于 i=1,2,3i=1,2,3,从上到下第 ii 行所填数字之和为 hih_i
  • 对于 j=1,2,3j=1,2,3,从左到右第 jj 列所填数字之和为 wjw_j

例如,若 (h1,h2,h3)=(5,13,10)(h_1, h_2, h_3) = (5, 13, 10)(w1,w2,w3)=(6,13,9)(w_1, w_2, w_3) = (6, 13, 9),则以下三种方式都满足条件。(还有其他满足条件的方式。)

有多少种填数方式可以满足这些条件?

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

Problem Statement

You are given six integers: h1,h2,h3,w1,w2h_1, h_2, h_3, w_1, w_2, and w3w_3.
Consider writing a positive integer on each square of a 3×33 \times 3 grid so that all of the following conditions are satisfied:

  • For i=1,2,3i=1,2,3, the sum of numbers written in the ii-th row from the top is hih_i.
  • For j=1,2,3j=1,2,3, the sum of numbers written in the jj-th column from the left is wiw_i.

For example, if (h1,h2,h3)=(5,13,10)(h_1, h_2, h_3) = (5, 13, 10) and (w1,w2,w3)=(6,13,9)(w_1, w_2, w_3) = (6, 13, 9), then all of the following three ways satisfy the conditions. (There are other ways to satisfy the conditions.)

image

How many ways are there to write numbers to satisfy the conditions?

Constraints

  • 3h1,h2,h3,w1,w2,w3303 \leq h_1, h_2, h_3, w_1, w_2, w_3 \leq 30
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

h1h_1 h2h_2 h3h_3 w1w_1 w2w_2 w3w_3

Output

Print the number of ways to write numbers to satisfy the conditions.

Sample Input 1

3 4 6 3 3 7

Sample Output 1

1

The following is the only way to satisfy the conditions. Thus, 11 should be printed.

image2

Sample Input 2

3 4 5 6 7 8

Sample Output 2

0

There may not be a way to satisfy the conditions.

Sample Input 3

5 13 10 6 13 9

Sample Output 3

120

Sample Input 4

20 25 30 22 29 24

Sample Output 4

30613

update @ 2024/3/10 10:53:28

}