A - The Number of Even Pairs

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 100

問題文

N+M 個のボールがあります。各ボールには整数が 1 つ書かれています。
これらのボールに書かれている数について、

  • N 個のボールに書かれている数は偶数
  • M 個のボールに書かれている数は奇数

であることがわかっています。

これらの N+M 個のボールの中から 2 つ選んで、書かれた数の和が偶数になる方法の数を求めてください。選ぶ順序は考慮しません。

なお、この方法の数はボールに書かれている整数の実際の値によらないことが示せます。

制約

  • 0 \leq N,M \leq 100
  • 2 \leq N+M
  • 入力はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

N M

出力

答えを出力せよ。


入力例 1

2 1

出力例 1

1

例えば 3 つのボールに書かれている数がそれぞれ 1,2,4 であるとすると、

  • 1 が書かれたボールと 2 が書かれたボールを選ぶと、和は奇数
  • 1 が書かれたボールと 4 が書かれたボールを選ぶと、和は奇数
  • 2 が書かれたボールと 4 が書かれたボールを選ぶと、和は偶数

であるので、答えは 1 です。


入力例 2

4 3

出力例 2

9

入力例 3

1 1

出力例 3

0

入力例 4

13 3

出力例 4

81

入力例 5

0 3

出力例 5

3

Score : 100 points

Problem Statement

We have N+M balls, each of which has an integer written on it.
It is known that:

  • The numbers written on N of the balls are even.
  • The numbers written on M of the balls are odd.

Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written on the balls.

Constraints

  • 0 \leq N,M \leq 100
  • 2 \leq N+M
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the answer.


Sample Input 1

2 1

Sample Output 1

1

For example, let us assume that the numbers written on the three balls are 1,2,4.

  • If we choose the two balls with 1 and 2, the sum is odd;
  • If we choose the two balls with 1 and 4, the sum is odd;
  • If we choose the two balls with 2 and 4, the sum is even.

Thus, the answer is 1.


Sample Input 2

4 3

Sample Output 2

9

Sample Input 3

1 1

Sample Output 3

0

Sample Input 4

13 3

Sample Output 4

81

Sample Input 5

0 3

Sample Output 5

3
B - String Palindrome

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 200

問題文

長さが奇数である文字列 S が以下の条件をすべて満たすとき、S は「強い回文」であるといいます。

  • S は回文である。
  • NS の長さとするとき、S1 文字目から (N-1)/2 文字目まで(両端含む)からなる文字列は回文である。
  • S(N+3)/2 文字目から N 文字目まで(両端含む)からなる文字列は回文である。

S が強い回文かどうかを判定してください。

制約

  • S は英小文字のみからなる
  • S の長さは 3 以上 99 以下の奇数

入力

入力は以下の形式で標準入力から与えられる。

S

出力

S が強い回文ならば Yes 、 強い回文でないならば No と出力せよ。


入力例 1

akasaka

出力例 1

Yes
  • Sakasaka
  • S1 文字目から 3 文字目までからなる文字列は aka
  • S5 文字目から 7 文字目までからなる文字列は aka

これらはすべて回文であるため、S は強い回文です。


入力例 2

level

出力例 2

No

入力例 3

atcoder

出力例 3

No

Score : 200 points

Problem Statement

A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:

  • S is a palindrome.
  • Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.
  • The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.

Determine whether S is a strong palindrome.

Constraints

  • S consists of lowercase English letters.
  • The length of S is an odd number between 3 and 99 (inclusive).

Input

Input is given from Standard Input in the following format:

S

Output

If S is a strong palindrome, print Yes; otherwise, print No.


Sample Input 1

akasaka

Sample Output 1

Yes
  • S is akasaka.
  • The string formed by the 1-st through the 3-rd characters is aka.
  • The string formed by the 5-th through the 7-th characters is aka. All of these are palindromes, so S is a strong palindrome.

Sample Input 2

level

Sample Output 2

No

Sample Input 3

atcoder

Sample Output 3

No
C - Maximum Volume

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 300

問題文

正の整数 L が与えられます。 縦、横、高さの長さ (それぞれ、整数でなくてもかまいません) の合計が L の直方体としてありうる体積の最大値を求めてください。

制約

  • 1 ≤ L ≤ 1000
  • L は整数

入力

入力は以下の形式で標準入力から与えられる。

L

出力

縦、横、高さの長さの合計が L の直方体としてありうる体積の最大値を出力せよ。 なお、想定解答との絶対誤差または相対誤差が 10^{-6} 以下であれば正解として扱われる。


入力例 1

3

出力例 1

1.000000000000

例えば 縦 0.8 、横 1 、高さ 1.2 の直方体の体積は 0.96 です。

一方、縦 1 、横 1 、高さ 1 とすると直方体の体積は 1 で、より体積が大きいです。


入力例 2

999

出力例 2

36926037.000000000000

Score : 300 points

Problem Statement

Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.

Constraints

  • 1 ≤ L ≤ 1000
  • L is an integer.

Input

Input is given from Standard Input in the following format:

L

Output

Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. Your output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.


Sample Input 1

3

Sample Output 1

1.000000000000

For example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.

On the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.


Sample Input 2

999

Sample Output 2

36926037.000000000000
D - Banned K

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 400

問題文

ボールが N 個あり、 i 番目のボールには整数 A_i が書かれています。
k=1,2,...,N に対して以下の問題を解いて、答えをそれぞれ出力してください。

  • k 番目のボールを除いた N-1 個のボールから、書かれている整数が等しいような異なる 2 つのボールを選び出す方法の数を求めてください。選ぶ順序は考慮しません。

制約

  • 3 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq N
  • 入力はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 ... A_N

出力

k=1,2,...,N に対する答えを順番に一行ずつ出力せよ。


入力例 1

5
1 1 2 1 2

出力例 1

2
2
3
2
3

例えば k=1 のとき、残りのボールに書かれている数はそれぞれ {1,2,1,2} です。
この中から書かれている数が等しいような異なる 2 つのボールを選び出す方法は 2 通りあります。
したがって、 k=1 に対する問題の答えは 2 です。


入力例 2

4
1 2 3 4

出力例 2

0
0
0
0

どの 2 つのボールを選び出しても、書かれている数は等しくありません。


入力例 3

5
3 3 3 3 3

出力例 3

6
6
6
6
6

どの 2 つのボールを選び出しても、書かれている数が等しいです。


入力例 4

8
1 2 1 4 2 1 4 1

出力例 4

5
7
5
7
7
5
7
5

Score : 400 points

Problem Statement

We have N balls. The i-th ball has an integer A_i written on it.
For each k=1, 2, ..., N, solve the following problem and print the answer.

  • Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Constraints

  • 3 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

For each k=1,2,...,N, print a line containing the answer.


Sample Input 1

5
1 1 2 1 2

Sample Output 1

2
2
3
2
3

Consider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.
From these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.
Thus, the answer for k=1 is 2.


Sample Input 2

4
1 2 3 4

Sample Output 2

0
0
0
0

No two balls have equal numbers written on them.


Sample Input 3

5
3 3 3 3 3

Sample Output 3

6
6
6
6
6

Any two balls have equal numbers written on them.


Sample Input 4

8
1 2 1 4 2 1 4 1

Sample Output 4

5
7
5
7
7
5
7
5
E - Dividing Chocolate

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 500

問題文

H マス、横 W マスのグリッドに区切られたチョコレートがあります。

上から i 行目、左から j 列目にあるマス (i,j) のチョコレートは、S_{i,j}0 のとき普通のチョコレートであり、1 のときホワイトチョコレートです。

このチョコレートに対して、マスの境界に沿った直線によってグリッド全体の端から端まで割る操作を何度か行い、いくつかのブロックに分割します。

分割後のどのブロックにもホワイトチョコレートのマスが K マス以下しか含まれないようにするためには、最小で操作を何回行う必要があるか求めてください。

制約

  • 1 \leq H \leq 10
  • 1 \leq W \leq 1000
  • 1 \leq K \leq H \times W
  • S_{i,j}01

入力

入力は以下の形式で標準入力から与えられる。

H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W}

出力

分割後のどのブロックにもホワイトチョコレートのマスが K マス以下しか含まれないようにするため必要な操作回数の最小値を出力せよ。


入力例 1

3 5 4
11100
10001
00111

出力例 1

2

例えば左の図のように 1 行目と 2 行目の間と、3 列目と 4 列目の間の 2 か所で割ればよいです。

右の2つの図のような割り方はできないことに注意してください。

図


入力例 2

3 5 8
11100
10001
00111

出力例 2

0

操作を行う必要はありません。


入力例 3

4 10 4
1110010010
1000101110
0011101001
1101000111

出力例 3

3

Score : 500 points

Problem Statement

We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares.

The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is 0, and white if S_{i,j} is 1.

We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.

How many times do we need to cut the bar so that every block after the cuts has K or less white squares?

Constraints

  • 1 \leq H \leq 10
  • 1 \leq W \leq 1000
  • 1 \leq K \leq H \times W
  • S_{i,j} is 0 or 1.

Input

Input is given from Standard Input in the following format:

H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W}

Output

Print the number of minimum times the bar needs to be cut so that every block after the cuts has K or less white squares.


Sample Input 1

3 5 4
11100
10001
00111

Sample Output 1

2

For example, cutting between the 1-st and 2-nd rows and between the 3-rd and 4-th columns - as shown in the figure to the left - works.

Note that we cannot cut the bar in the ways shown in the two figures to the right.

Figure


Sample Input 2

3 5 8
11100
10001
00111

Sample Output 2

0

No cut is needed.


Sample Input 3

4 10 4
1110010010
1000101110
0011101001
1101000111

Sample Output 3

3
F - Knapsack for All Segments

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 600

問題文

長さ N の整数列 A_1, A_2, \ldots, A_N と正の整数 S が与えられます。
1\leq L \leq R \leq N をみたす整数 (L, R) の組について、f(L, R) を以下のように定めます。

  • L \leq x_1 < x_2 < \cdots < x_k \leq R かつ A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S を満たすような整数列 (x_1, x_2, \ldots , x_k) の個数

1\leq L \leq R\leq N を満たす整数 (L, R) の組すべてに対する f(L, R) の和を求めてください。ただし、答えは非常に大きくなることがあるので、998244353 で割ったあまりを出力してください。

制約

  • 入力は全て整数である。
  • 1 \leq N \leq 3000
  • 1 \leq S \leq 3000
  • 1 \leq A_i \leq 3000

入力

入力は以下の形式で標準入力から与えられる。

N S
A_1 A_2 ... A_N

出力

f(L, R) の和を 998244353 で割ったあまりを出力せよ。


入力例 1

3 4
2 2 4

出力例 1

5

それぞれ以下のように計算できて、その和は 5 です。

  • f(1,1) = 0
  • f(1,2) = 1 ((1, 2)1 つ)
  • f(1,3) = 2 ((1, 2)(3)2 つ)
  • f(2,2) = 0
  • f(2,3) = 1 ((3)1 つ)
  • f(3,3) = 1 ((3)1 つ)

入力例 2

5 8
9 9 9 9 9

出力例 2

0

入力例 3

10 10
3 1 4 1 5 9 2 6 5 3

出力例 3

152

Score : 600 points

Problem Statement

Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S.
For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows:

  • f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S.

Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 3000
  • 1 \leq S \leq 3000
  • 1 \leq A_i \leq 3000

Input

Input is given from Standard Input in the following format:

N S
A_1 A_2 ... A_N

Output

Print the sum of f(L, R), modulo 998244353.


Sample Input 1

3 4
2 2 4

Sample Output 1

5

The value of f(L, R) for each pair is as follows, for a total of 5.

  • f(1,1) = 0
  • f(1,2) = 1 (for the sequence (1, 2))
  • f(1,3) = 2 (for (1, 2) and (3))
  • f(2,2) = 0
  • f(2,3) = 1 (for (3))
  • f(3,3) = 1 (for (3))

Sample Input 2

5 8
9 9 9 9 9

Sample Output 2

0

Sample Input 3

10 10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

152