#abc266g. G - Yet Another RGB Sequence

G - Yet Another RGB Sequence

Score : 600600 points

问题描述

给定整数 RRGGBBKK。有多少个由 RGB 组成的字符串 SS 满足以下所有条件?请计算满足条件的字符串数量模 998244353998244353 的结果。

  • 字符串 SSRGB 出现的次数分别为 RRGGBB
  • 字符串 SS 中作为(连续)子串出现的 RG 的次数为 KK

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

Problem Statement

You are given integers RR, GG, BB, and KK. How many strings SS consisting of R, G, and B satisfy all of the conditions below? Find the count modulo 998244353998244353.

  • The number of occurrences of R, G, and B in SS are RR, GG, and BB, respectively.
  • The number of occurrences of RG as (contiguous) substrings in SS is KK.

Constraints

  • 1R,G,B1061 \leq R,G,B\leq 10^6
  • 0Kmin(R,G)0 \leq K \leq \mathrm{min}(R,G)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

RR GG BB KK

Output

Print the answer.

Sample Input 1

2 1 1 1

Sample Output 1

6

The following six strings satisfy the conditions.

  • RRGB
  • RGRB
  • RGBR
  • RBRG
  • BRRG
  • BRGR

Sample Input 2

1000000 1000000 1000000 1000000

Sample Output 2

80957240

Find the count modulo 998244353998244353.

update @ 2024/3/10 11:15:28