Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字のみからなる文字列 S が与えられます。
S の各文字を英大文字に変換して得られる文字列 T を出力してください。
制約
- S は英小文字のみからなる、長さが 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
T を出力せよ。
入力例 1
abc
出力例 1
ABC
abc
の各文字を英大文字に変換すると ABC
になります。
入力例 2
a
出力例 2
A
入力例 3
abcdefghjiklnmoqprstvuwxyz
出力例 3
ABCDEFGHJIKLNMOQPRSTVUWXYZ
Score : 100 points
Problem Statement
You are given a string S consisting of lowercase English letters.
Uppercase each character of S and print the resulting string T.
Constraints
- S is a string consisting of lowercase English letters whose length is between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print T.
Sample Input 1
abc
Sample Output 1
ABC
Uppercase each character of abc
, and you have ABC
.
Sample Input 2
a
Sample Output 2
A
Sample Input 3
abcdefghjiklnmoqprstvuwxyz
Sample Output 3
ABCDEFGHJIKLNMOQPRSTVUWXYZ
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder 村には N 本の橋があり、i 本目( i は 1 以上 N 以下の整数)の橋の高さは H_i です。
ここで、AtCoder 村にある N 本の橋のうち、どの相異なる 2 本の橋も高さが異なります。
AtCoder 村で最も高い橋は何本目の橋か出力してください。
制約
- 1\leq N \leq 100
- 1\leq H_i \leq 10^9
- H_i はすべて異なる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N H_1 H_2 \ldots H_N
出力
AtCoder 村で最も高い橋は何本目の橋かを、整数で出力せよ。
入力例 1
3 50 80 70
出力例 1
2
AtCoder 村には 3 本の橋があります。
1,2,3 本目の橋の高さはそれぞれ, 50,80,70 であり、
最も高い橋は 2 本目の橋です。
よって、2 を出力します。
入力例 2
1 1000000000
出力例 2
1
AtCoder 村に橋が 1 本しか存在しないため、2 本目以降の橋は存在せず、最も高い橋は 1 本目の橋となります。
入力例 3
10 22 75 26 45 72 81 47 29 97 2
出力例 3
9
AtCoder 村には 10 本の橋があり、それらのうち最も高い橋は 9 番目の橋(高さは 97 )です。
Score : 100 points
Problem Statement
There are N bridges in AtCoder Village. The height of the bridge numbered i is H_i (i is an integer between 1 and N).
Every two different bridges in the village have different heights.
Print the number representing the highest bridge in the village.
Constraints
- 1\leq N \leq 100
- 1\leq H_i \leq 10^9
- All H_i are different.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N H_1 H_2 \ldots H_N
Output
Print the integer representing the highest bridge in AtCoder village.
Sample Input 1
3 50 80 70
Sample Output 1
2
The village has three bridges.
The first, second, and third bridges have heights of 50, 80, and 70, respectively,
so the second bridge is the highest.
Thus, 2 should be printed.
Sample Input 2
1 1000000000
Sample Output 2
1
The village has only one bridge, so the first bridge is the highest.
Sample Input 3
10 22 75 26 45 72 81 47 29 97 2
Sample Output 3
9
The village has ten bridges, and the ninth bridge (with a height of 97) is the highest.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数 N が与えられます。
N 行 N 列のマス目があり、上から i 行目、左から j 列目のマスには数字 A_{i,j} が書かれています。
このマス目は上下および左右がつながっているものとします。つまり以下が全て成り立ちます。
- (1,i) の上のマスは (N,i) であり、(N,i) の下のマスは (1,i) である。(1\le i\le N)
- (i,1) の左のマスは (i,N) であり、(i,N) の右のマスは (i,1) である。(1\le i\le N)
高橋君は、上下左右および斜めの 8 方向のうちいずれかを初めに選びます。そして、好きなマスから決めた方向に 1 マス移動することを N-1 回繰り返します。
高橋君は N 個のマス上を移動することになりますが、高橋君が通ったマスに書かれている数字を左から通った順番に並べた整数としてあり得る最大のものを求めてください。
制約
- 1 \le N \le 10
- 1 \le A_{i,j} \le 9
- 入力はすべて整数。
入力
入力は以下の形式で標準入力から与えられる。
N A_{1,1}A_{1,2}\dots A_{1,N} A_{2,1}A_{2,2}\dots A_{2,N} \vdots A_{N,1}A_{N,2}\dots A_{N,N}
出力
答えを出力せよ。
入力例 1
4 1161 1119 7111 1811
出力例 1
9786
高橋君が上から 2 行目、左から 4 列目のマスから出発し、右下に進むことで、通ったマスに書かれた数字を並べ 9786 を作ることができます。 9786 より大きい値を作ることはできないため、9786 が解です。
入力例 2
10 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111
出力例 2
1111111111
32bit整数型に答えが収まるとは限らないことに注意してください。
Score : 200 points
Problem Statement
You are given a positive integer N.
We have a grid with N rows and N columns, where the square at the i-th row from the top and j-th column from the left has a digit A_{i,j} written on it.
Assume that the upper and lower edges of this grid are connected, as well as the left and right edges. In other words, all of the following holds.
- (N,i) is just above (1,i), and (1,i) is just below (N,i). (1\le i\le N).
- (i,N) is just to the left of (i,1), and (i,1) is just to the right of (i,N). (1\le i\le N).
Takahashi will first choose one of the following eight directions: up, down, left, right, and the four diagonal directions. Then, he will start on a square of his choice and repeat moving one square in the chosen direction N-1 times.
In this process, Takahashi visits N squares. Find the greatest possible value of the integer that is obtained by arranging the digits written on the squares visited by Takahashi from left to right in the order visited by him.
Constraints
- 1 \le N \le 10
- 1 \le A_{i,j} \le 9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_{1,1}A_{1,2}\dots A_{1,N} A_{2,1}A_{2,2}\dots A_{2,N} \vdots A_{N,1}A_{N,2}\dots A_{N,N}
Output
Print the answer.
Sample Input 1
4 1161 1119 7111 1811
Sample Output 1
9786
If Takahashi starts on the square at the 2-nd row from the top and 4-th column from the left and goes down and to the right, the integer obtained by arranging the digits written on the visited squares will be 9786. It is impossible to make a value greater than 9786, so the answer is 9786.
Sample Input 2
10 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111
Sample Output 2
1111111111
Note that the answer may not fit into a 32-bit integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
この問題は 1 つの入力ファイルに複数のテストケースが含まれる問題です。
はじめに整数 T が与えられます。T 個のテストケースについて次の問題を解いてください。
- N 個の正整数 A_1, A_2, ..., A_N があります。このうち奇数は何個ありますか?
制約
- 1 \leq T \leq 100
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。ここで \text{test}_i は i 番目のテストケースを意味する。
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
各テストケースは以下の形式で与えられる。
N A_1 A_2 \dots A_N
出力
T 行出力せよ。i 行目には i 番目のテストケースに対する答えを出力せよ。
入力例 1
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000
出力例 1
2 1 5 0
この入力は 4 個のテストケースが含まれています。
入力の 2 行目と 3 行目が 1 番目のテストケースに対応する入力で、N = 3, A_1 = 1, A_2 = 2, A_3 = 3 になります。
A_1, A_2, A_3 のうち奇数は全部で 2 個なので 1 行目に 2 を出力します。
Score : 200 points
Problem Statement
In this problem, an input file contains multiple test cases.
You are first given an integer T. Solve the following problem for T test cases.
- We have N positive integers A_1, A_2, ..., A_N. How many of them are odd?
Constraints
- 1 \leq T \leq 100
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where \text{test}_i represents the i-th test case:
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
Each test case is in the following format:
N A_1 A_2 \dots A_N
Output
Print T lines. The i-th line should contain the answer for the i-th test case.
Sample Input 1
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000
Sample Output 1
2 1 5 0
This input contains four test cases.
The second and third lines correspond to the first test case, where N = 3, A_1 = 1, A_2 = 2, A_3 = 3.
We have two odd numbers in A_1, A_2, and A_3, so the first line should contain 2.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
xy 座標平面上の 2 つの格子点 (x_1, y_1), (x_2, y_2) からの距離がともに \sqrt{5} である格子点は存在しますか?
注記
xy 座標平面上にある点のうち、x 座標と y 座標がともに整数である点を格子点と呼びます。
また、xy 平面上の 2 点 (a, b), (c, d) の距離をユークリッド距離 \sqrt{(a - c)^2 + (b-d)^2} として定義します。
参考として、xy 平面の (0, 0) の上に黒丸を、(0, 0) からの距離が \sqrt{5} となる格子点の上に白丸を書いた図は以下のようになります。(x,y いずれかが整数となる部分に目盛り線を引いています。)
制約
- -10^9 \leq x_1 \leq 10^9
- -10^9 \leq y_1 \leq 10^9
- -10^9 \leq x_2 \leq 10^9
- -10^9 \leq y_2 \leq 10^9
- (x_1, y_1) \neq (x_2, y_2)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
x_1 y_1 x_2 y_2
出力
条件を満たす格子点が存在する場合は Yes
を、存在しない場合は No
を出力せよ。
入力例 1
0 0 3 3
出力例 1
Yes
- 点 (2,1) と (x_1, y_1) の距離は \sqrt{(0-2)^2 + (0-1)^2} = \sqrt{5}
- 点 (2,1) と (x_2, y_2) の距離は \sqrt{(3-2)^2 + (3-1)^2} = \sqrt{5}
- 点 (2, 1) は格子点
なので点 (2, 1) は条件を満たします。よって Yes
を出力します。
なお、点 (1, 2) も条件を満たすことが同様にして確認できます。
入力例 2
0 1 2 3
出力例 2
No
条件を満たす格子点は存在しません。よって No
を出力します。
入力例 3
1000000000 1000000000 999999999 999999999
出力例 3
Yes
点 (10^9 + 1, 10^9 - 2) および点 (10^9 - 2, 10^9 + 1)が条件を満たします。
Score : 300 points
Problem Statement
On an xy-coordinate plane, is there a lattice point whose distances from two lattice points (x_1, y_1) and (x_2, y_2) are both \sqrt{5}?
Notes
A point on an xy-coordinate plane whose x and y coordinates are both integers is called a lattice point.
The distance between two points (a, b) and (c, d) is defined to be the Euclidean distance between them, \sqrt{(a - c)^2 + (b-d)^2}.
The following figure illustrates an xy-plane with a black circle at (0, 0) and white circles at the lattice points whose distances from (0, 0) are \sqrt{5}. (The grid shows where either x or y is an integer.)
Constraints
- -10^9 \leq x_1 \leq 10^9
- -10^9 \leq y_1 \leq 10^9
- -10^9 \leq x_2 \leq 10^9
- -10^9 \leq y_2 \leq 10^9
- (x_1, y_1) \neq (x_2, y_2)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
x_1 y_1 x_2 y_2
Output
If there is a lattice point satisfying the condition, print Yes
; otherwise, print No
.
Sample Input 1
0 0 3 3
Sample Output 1
Yes
- The distance between points (2,1) and (x_1, y_1) is \sqrt{(0-2)^2 + (0-1)^2} = \sqrt{5};
- the distance between points (2,1) and (x_2, y_2) is \sqrt{(3-2)^2 + (3-1)^2} = \sqrt{5};
- point (2, 1) is a lattice point,
so point (2, 1) satisfies the condition. Thus, Yes
should be printed.
One can also assert in the same way that (1, 2) also satisfies the condition.
Sample Input 2
0 1 2 3
Sample Output 2
No
No lattice point satisfies the condition, so No
should be printed.
Sample Input 3
1000000000 1000000000 999999999 999999999
Sample Output 3
Yes
Point (10^9 + 1, 10^9 - 2) and point (10^9 - 2, 10^9 + 1) satisfy the condition.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君と青木君は、それぞれ N 個のボールに M 本のひもを取り付けたおもちゃを持っています。
高橋君のおもちゃにおいて、ボールには 1, \dots, N と番号が付けられており、i \, (1 \leq i \leq M) 本目のひもはボール A_i とボール B_i を結んでいます。
青木君のおもちゃにおいても同様に、ボールには 1, \dots, N と番号が付けられており、i \, (1 \leq i \leq M) 本目のひもはボール C_i とボール D_i を結んでいます。
それぞれのおもちゃにおいて、同一のボールを結ぶようなひもは存在せず、2 つのボールを 2 本以上の異なるひもが結んでいることはありません。
すぬけ君は、2 人のおもちゃが同じ形であるかどうか気になっています。
ここで、2 人のおもちゃが同じ形であるとは、以下の条件を満たす数列 P が存在することをいいます。
- P は (1, \dots, N) を並べ替えて得られる。
- 任意の 1 以上 N 以下の整数 i, j に対し、以下が成り立つ。
- 高橋君のおもちゃにおいてボール i, j がひもで繋がれていることと、青木君のおもちゃにおいてボール P_i, P_j がひもで繋がれていることは同値である。
2 人のおもちゃが同じ形であるなら Yes
、そうでないなら No
と出力してください。
制約
- 1 \leq N \leq 8
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
- (A_i, B_i) \neq (A_j, B_j) \, (i \neq j)
- 1 \leq C_i \lt D_i \leq N \, (1 \leq i \leq M)
- (C_i, D_i) \neq (C_j, D_j) \, (i \neq j)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 \vdots A_M B_M C_1 D_1 \vdots C_M D_M
出力
2 人のおもちゃが同じ形であるなら Yes
、そうでないなら No
と出力せよ。
入力例 1
4 4 1 2 1 3 1 4 3 4 1 3 1 4 2 3 3 4
出力例 1
Yes
高橋君のおもちゃは下図の左側のような形をしており、青木君のおもちゃは下図の右側のような形をしています。
次の図から、2 人のおもちゃが同じ形であることがわかります。例えば P = (3, 2, 1, 4) とすると問題文中の条件を満たします。
入力例 2
5 6 1 2 1 3 1 4 3 4 3 5 4 5 1 2 1 3 1 4 1 5 3 5 4 5
出力例 2
No
2 人のおもちゃは同じ形ではありません。
入力例 3
8 0
出力例 3
Yes
Score : 300 points
Problem Statement
Takahashi and Aoki each have a toy made by attaching M cords to N balls.
In Takahashi's toy, the balls are numbered 1, \dots, N, and the i-th cord ties Ball A_i and B_i.
Similarly, in Aoki's toy, the balls are numbered 1, \dots, N, and the i-th cord ties Ball C_i and D_i.
In each toy, no cord ties a ball to itself, and no two balls are tied by two or more different cords.
Snuke is wondering whether the two toys have the same shape.
Here, they are said to have the same shape when there is a sequence P that satisfies the conditions below.
- P is a permutation of (1, \dots, N).
- For every pair of integers i, j between 1 and N (inclusive), the following holds.
- Balls i and j in Takahashi's toy are tied by a cord if and only if Balls P_i and P_j in Aoki's toy are tied by a cord.
If the two toys have the same shape, print Yes
; otherwise, print No
.
Constraints
- 1 \leq N \leq 8
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
- (A_i, B_i) \neq (A_j, B_j) \, (i \neq j)
- 1 \leq C_i \lt D_i \leq N \, (1 \leq i \leq M)
- (C_i, D_i) \neq (C_j, D_j) \, (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 B_1 \vdots A_M B_M C_1 D_1 \vdots C_M D_M
Output
If the two toys have the same shape, print Yes
; otherwise, print No
.
Sample Input 1
4 4 1 2 1 3 1 4 3 4 1 3 1 4 2 3 3 4
Sample Output 1
Yes
Takahashi's toy is illustrated on the left in the figure below, and Aoki's is illustrated on the right.
The following figure shows that the two toys have the same shape. The condition in the statement is satisfied when P = (3, 2, 1, 4), for example.
Sample Input 2
5 6 1 2 1 3 1 4 3 4 3 5 4 5 1 2 1 3 1 4 1 5 3 5 4 5
Sample Output 2
No
The two toys do not have the same shape.
Sample Input 3
8 0
Sample Output 3
Yes
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は N 種類の硬貨をそれぞれ何枚か持っており、 具体的には、1\leq i\leq N について A_i 円硬貨を B_i 枚持っています。
高橋君が現在持っている硬貨を用いて、(お釣りが出ないように)ちょうど X 円を支払うことができるか判定してください。
制約
- 1\leq N\leq 50
- 1\leq X\leq 10^4
- 1\leq A_i\leq 100
- 1\leq B_i\leq 50
- A_i はすべて異なる。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
高橋君が現在持っている硬貨を用いてちょうど X 円を支払うことができる場合は Yes
を、
できない場合は No
を出力せよ。
入力例 1
2 19 2 3 5 6
出力例 1
Yes
高橋君は 2 円硬貨を 3 枚、5 円硬貨を 6 枚持っています。
このうち、2 円硬貨を 2 枚、5 円硬貨を 3 枚用いることでちょうど 2\times 2+5\times 3=19 円を支払うことができます。
よって、Yes
を出力します。
入力例 2
2 18 2 3 5 6
出力例 2
No
持っている硬貨をどのように組み合わせてもちょうど 18 円を支払うことはできません。
よって、No
を出力します。
入力例 3
3 1001 1 1 2 1 100 10
出力例 3
Yes
1 枚も使用しない硬貨が存在しても構いません。
Score : 400 points
Problem Statement
Takahashi has N kinds of coins; specifically, for 1\leq i\leq N, he has B_i coins worth A_i yen (the currency in Japan) each.
Determine if Takahashi can pay exactly X yen (without change) with the coins he currently has.
Constraints
- 1\leq N\leq 50
- 1\leq X\leq 10^4
- 1\leq A_i\leq 100
- 1\leq B_i\leq 50
- A_i are pairwise distinct.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N X A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print Yes
if Takahashi can pay exactly X yen with the coins he currently has;
print No
otherwise.
Sample Input 1
2 19 2 3 5 6
Sample Output 1
Yes
Takahashi has three 2-yen coins and six 5-yen coins.
He can use two 2-yen coins and three 5-yen coins to pay exactly 2\times 2+5\times 3=19 yen.
Thus, Yes
should be printed.
Sample Input 2
2 18 2 3 5 6
Sample Output 2
No
There is no combination of the coins that he can use to pay exactly 18 yen.
Thus, No
should be printed.
Sample Input 3
3 1001 1 1 2 1 100 10
Sample Output 3
Yes
He need not use all kinds of coins.
Time Limit: 3.5 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 頂点 M 辺の単純無向グラフがあり、各頂点には 1,\ldots,N と番号が付けられています。 i=1,\ldots,M に対し、 i 番目の辺は頂点 a_i と頂点 b_i を結びます。また、各頂点の次数は 3 以下です。
i=1,\ldots,Q に対し、次のクエリに答えてください。
- 頂点 x_i との距離が k_i 以下であるような頂点の番号の総和を求めよ。
制約
- 1 \leq N \leq 1.5 \times 10^5
- 0 \leq M \leq \min (\frac{N(N-1)}{2},\frac{3N}{2})
- 1 \leq a_i \lt b_i \leq N
- i\neq j ならば (a_i,b_i) \neq (a_j,b_j)
- 与えられるグラフの各頂点の次数は 3 以下
- 1 \leq Q \leq 1.5 \times 10^5
- 1 \leq x_i \leq N
- 0 \leq k_i \leq 3
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M a_1 b_1 \vdots a_M b_M Q x_1 k_1 \vdots x_Q k_Q
出力
Q 行出力せよ。 i 行目には i 番目のクエリへの答えを出力せよ。
入力例 1
6 5 2 3 3 4 3 5 5 6 2 6 7 1 1 2 2 2 0 2 3 4 1 6 0 4 3
出力例 1
1 20 2 20 7 6 20
1 番目のクエリでは、頂点 1 との距離が 1 以下であるような頂点は頂点 1 のみなので 1 が答えです。
2 番目のクエリでは、頂点 2 との距離が 2 以下であるような頂点は頂点 2,3,4,5,6 なのでこれらの総和の 20 が答えになります。
3 番目以降のクエリも同様にして答えを求められます。
Score : 500 points
Problem Statement
We have a simple undirected graph with N vertices and M edges. The vertices are numbered 1,\ldots,N. For each i=1,\ldots,M, the i-th edge connects Vertex a_i and Vertex b_i. Additionally, the degree of each vertex is at most 3.
For each i=1,\ldots,Q, answer the following query.
- Find the sum of indices of vertices whose distances from Vertex x_i are at most k_i.
Constraints
- 1 \leq N \leq 1.5 \times 10^5
- 0 \leq M \leq \min (\frac{N(N-1)}{2},\frac{3N}{2})
- 1 \leq a_i \lt b_i \leq N
- (a_i,b_i) \neq (a_j,b_j), if i\neq j.
- The degree of each vertex in the graph is at most 3.
- 1 \leq Q \leq 1.5 \times 10^5
- 1 \leq x_i \leq N
- 0 \leq k_i \leq 3
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M a_1 b_1 \vdots a_M b_M Q x_1 k_1 \vdots x_Q k_Q
Output
Print Q lines. The i-th line should contain the answer to the i-th query.
Sample Input 1
6 5 2 3 3 4 3 5 5 6 2 6 7 1 1 2 2 2 0 2 3 4 1 6 0 4 3
Sample Output 1
1 20 2 20 7 6 20
For the 1-st query, the only vertex whose distance from Vertex 1 is at most 1 is Vertex 1, so the answer is 1.
For the 2-nd query, the vertices whose distances from Vertex 2 are at most 2 are Vertex 2, 3, 4, 5, and 6, so the answer is their sum, 20.
The 3-rd and subsequent queries can be answered similarly.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 段からなるタイプライターがあります。このうち、上から i 段目のキーでは文字列 S_i に含まれる文字が打てます。
このキーボードを使って、以下のルールで文字列をひとつ入力することを考えます。
- まず、整数 1 \le k \le N を選択する。
- その後、空文字列から始めて、上から k 段目にあるキーだけを使ってちょうど L 文字の文字列を入力する。
このルールに従って入力可能な L 文字の文字列は何通りありますか? 答えは非常に大きくなる場合があるので 998244353 で割った余りを出力してください。
制約
- N,L は整数
- 1 \le N \le 18
- 1 \le L \le 10^9
- S_i は
abcdefghijklmnopqrstuvwxyz
の(連続とは限らない)空でない部分列
入力
入力は以下の形式で標準入力から与えられる。
N L S_1 S_2 \dots S_N
出力
答えを出力せよ。
入力例 1
2 2 ab ac
出力例 1
7
入力可能な文字列は aa
, ab
, ac
, ba
, bb
, ca
, cc
の 7 つです。
入力例 2
4 3 abcdefg hijklmnop qrstuv wxyz
出力例 2
1352
入力例 3
5 1000000000 abc acde cefg abcfh dghi
出力例 3
346462871
答えを 998244353 で割った余りを出力してください。
Score : 500 points
Problem Statement
We have a typewriter with N rows. The keys in the i-th row from the top can type the characters in a string S_i.
Let us use this keyboard to enter a string, as follows.
- First, choose an integer 1 \le k \le N.
- Then, start with an empty string and only use the keys in the k-th row from the top to enter a string of length exactly L.
How many strings of length L can be entered in this way? Since the answer can be enormous, print it modulo 998244353.
Constraints
- N and L are integers.
- 1 \le N \le 18
- 1 \le L \le 10^9
- S_i is a (not necessarily contiguous) non-empty subsequence of
abcdefghijklmnopqrstuvwxyz
.
Input
Input is given from Standard Input in the following format:
N L S_1 S_2 \dots S_N
Output
Print the answer.
Sample Input 1
2 2 ab ac
Sample Output 1
7
We can enter seven strings: aa
, ab
, ac
, ba
, bb
, ca
, cc
.
Sample Input 2
4 3 abcdefg hijklmnop qrstuv wxyz
Sample Output 2
1352
Sample Input 3
5 1000000000 abc acde cefg abcfh dghi
Sample Output 3
346462871
Be sure to print the answer modulo 998244353.