D - Yet Another ABC String
Editorial
/


Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
整数 が与えられます.
A
, B
, C
からなる文字列 であって,以下の条件をすべて満たすものの個数を で割った余りを求めてください.
- に含まれる
A
,B
,C
の個数はそれぞれ 個である. - は(連続する)部分文字列として,
ABC
,BCA
,CAB
のいずれも含まない.
制約
- 入力される値はすべて整数である
入力
入力は以下の形式で標準入力から与えられる.
出力
答えを出力せよ.
入力例 1Copy
Copy
1 1 1
出力例 1Copy
Copy
3
条件を満たす文字列は,ACB
, CBA
, BAC
の つです.
入力例 2Copy
Copy
2 2 2
出力例 2Copy
Copy
42
入力例 3Copy
Copy
96 11 46
出力例 3Copy
Copy
818015722
入力例 4Copy
Copy
125132 102271 152064
出力例 4Copy
Copy
128086069
Score : points
Problem Statement
You are given integers , , and .
How many strings consisting of A
, B
, and C
satisfy all of the following conditions? Find the count modulo .
- The number of occurrences of
A
,B
, andC
in are , , and , respectively. - contains none of
ABC
,BCA
, andCAB
as a (contiguous) substring.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
Copy
1 1 1
Sample Output 1Copy
Copy
3
The three strings that satisfy the conditions are ACB
, CBA
, and BAC
.
Sample Input 2Copy
Copy
2 2 2
Sample Output 2Copy
Copy
42
Sample Input 3Copy
Copy
96 11 46
Sample Output 3Copy
Copy
818015722
Sample Input 4Copy
Copy
125132 102271 152064
Sample Output 4Copy
Copy
128086069