A - chmin

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

配点 : 100 点

問題文

長さ N の整数列 A=(A_1,A_2,\dots,A_N) と整数 X が与えられます。
i=1,2,\dots,N の順に以下を行ってください。

  • もし A_i<X なら、 X=A_i に更新した上で 1 を出力する。
  • そうでないなら 0 を出力する。

制約

  • 入力は全て整数
  • 1 \le N,X,A_i \le 100

入力

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

N X
A_1 A_2 \dots A_N

出力

N 行出力せよ。
そのうち k 行目には、 i=k についての出力をせよ。


入力例 1

5 10
6 4 7 1 3

出力例 1

1
1
0
1
0
  • 最初、 X=10 です。
  • i=1 について、 A_1=6<X=10 なので、 X=6 に更新した上で 1 を出力します。
  • i=2 について、 A_2=4<X=6 なので、 X=4 に更新した上で 1 を出力します。
  • i=3 について、 A_3=7 \ge X=4 なので、 0 を出力します。
  • i=4 について、 A_4=1<X=4 なので、 X=1 に更新した上で 1 を出力します。
  • i=5 について、 A_5=3 \ge X=1 なので、 0 を出力します。

入力例 2

1 1
1

出力例 2

0

入力例 3

8 20
9 19 14 17 17 4 18 4

出力例 3

1
0
0
0
0
1
0
0

Score : 100 points

Problem Statement

You are given a length-N integer sequence A=(A_1,A_2,\dots,A_N) and an integer X.
For i=1,2,\dots,N in this order, do the following.

  • If A_i<X, update X=A_i and output 1.
  • Otherwise, output 0.

Constraints

  • All input values are integers.
  • 1 \le N,X,A_i \le 100

Input

The input is given from Standard Input in the following format:

N X
A_1 A_2 \dots A_N

Output

Output N lines.
The k-th line should contain the output for i=k.


Sample Input 1

5 10
6 4 7 1 3

Sample Output 1

1
1
0
1
0
  • Initially, X=10.
  • For i=1: since A_1=6<X=10, update X=6 and output 1.
  • For i=2: since A_2=4<X=6, update X=4 and output 1.
  • For i=3: since A_3=7 \ge X=4, output 0.
  • For i=4: since A_4=1<X=4, update X=1 and output 1.
  • For i=5: since A_5=3 \ge X=1, output 0.

Sample Input 2

1 1
1

Sample Output 2

0

Sample Input 3

8 20
9 19 14 17 17 4 18 4

Sample Output 3

1
0
0
0
0
1
0
0
B - Armor

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

配点 : 100 点

問題文

高橋君は鎧を着ています。

この鎧は威力(整数で表される攻撃の強さ)が D 以下の攻撃をすべて防ぎますが、威力が D より大きい攻撃は防ぎません。

この鎧は威力が A の攻撃を防ぎますか。

制約

  • 1 \leq A \leq 100
  • 1 \leq D \leq 100
  • 入力される値はすべて整数

入力

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

A D

出力

鎧が攻撃を防ぐなら Yes、防がないなら No と出力せよ。


入力例 1

4 5

出力例 1

Yes

この例では A = 4, D = 5 です。A = 4 は D = 5 以下であるため鎧は攻撃を防ぎ、答えは Yes です。


入力例 2

5 5

出力例 2

Yes

この例では A = 5, D = 5 です。A = 5 は D = 5 以下であるため鎧は攻撃を防ぎ、答えは Yes です。


入力例 3

6 5

出力例 3

No

この例では A = 6, D = 5 です。A = 6 は D = 5 以下でないため鎧は攻撃を防がず、答えは No です。

Score : 100 points

Problem Statement

Takahashi is wearing armor.

This armor blocks all attacks with power (strength represented as an integer) of D or less, but does not block attacks with power greater than D.

Does this armor block an attack with power A?

Constraints

  • 1 \leq A \leq 100
  • 1 \leq D \leq 100
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

A D

Output

Output Yes if the armor blocks the attack, and No otherwise.


Sample Input 1

4 5

Sample Output 1

Yes

In this sample, A = 4 and D = 5. Since A = 4 is at most D = 5, the armor blocks the attack, so the answer is Yes.


Sample Input 2

5 5

Sample Output 2

Yes

In this sample, A = 5 and D = 5. Since A = 5 is at most D = 5, the armor blocks the attack, so the answer is Yes.


Sample Input 3

6 5

Sample Output 3

No

In this sample, A = 6 and D = 5. Since A = 6 is not at most D = 5, the armor does not block the attack, so the answer is No.

C - Base 2

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

配点 : 200 点

問題文

0 と 1 からなる長さ 64 の数列 A=(A_0,A_1,\dots,A_{63}) が与えられます。

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} を求めてください。

制約

  • A_i は 0 または 1

入力

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

A_0 A_1 \dots A_{63}

出力

答えを整数として出力せよ。


入力例 1

1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

出力例 1

13

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13 です。


入力例 2

1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0

出力例 2

766067858140017173

Score : 200 points

Problem Statement

You are given a sequence A=(A_0,A_1,\dots,A_{63}) of length 64 consisting of 0 and 1.

Find A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63}.

Constraints

  • A_i is 0 or 1.

Input

The input is given from Standard Input in the following format:

A_0 A_1 \dots A_{63}

Output

Print the answer as an integer.


Sample Input 1

1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output 1

13

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13.


Sample Input 2

1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0

Sample Output 2

766067858140017173
D - Count Adjacent Cells

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

配点 : 200 点

問題文

H 行 W 列のグリッドがあります。上から i 行目、左から j 列目のマスをマス (i,j) と表します。

マス (x_1, y_1) とマス (x_2, y_2) が辺で隣接するとは、|x_1 - x_2| + |y_1 - y_2| = 1 が成り立つことをいいます。

すべてのマスについて、そのマスに辺で隣接するマスの個数を求めてください。

制約

  • 1 \leq H,W \leq 50
  • 入力される値はすべて整数

入力

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

H W

出力

答えを以下の形式で出力せよ。

x_{1,1} x_{1,2} \cdots x_{1,W}
x_{2,1} x_{2,2} \cdots x_{2,W}
\vdots
x_{H,1} x_{H,2} \cdots x_{H,W}

ここで、x_{i,j} はマス (i,j) に辺で隣接するマスの個数を表す。


入力例 1

4 5

出力例 1

2 3 3 3 2
3 4 4 4 3
3 4 4 4 3
2 3 3 3 2

マス (1, 5) に辺で隣接するマスは、マス (1, 4), (2, 5) の 2 個です。

マス (2, 3) に辺で隣接するマスは、マス (1, 3), (2, 2), (2, 4), (3, 3) の 4 個です。

マス (4, 2) に辺で隣接するマスは、マス (3, 2), (4, 1), (4, 3) の 3 個です。


入力例 2

1 1

出力例 2

0

マス (1,1) に辺で隣接するマスは存在しません。


入力例 3

12 8

出力例 3

2 3 3 3 3 3 3 2
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
2 3 3 3 3 3 3 2

Score : 200 points

Problem Statement

There is a grid with H rows and W columns. The cell at the i-th row from the top and the j-th column from the left is denoted as cell (i, j).

Cells (x_1, y_1) and (x_2, y_2) are said to be edge-adjacent when |x_1 - x_2| + |y_1 - y_2| = 1.

For every cell, find the number of cells that are edge-adjacent to it.

Constraints

  • 1 \leq H, W \leq 50
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

H W

Output

Output the answer in the following format:

x_{1,1} x_{1,2} \cdots x_{1,W}
x_{2,1} x_{2,2} \cdots x_{2,W}
\vdots
x_{H,1} x_{H,2} \cdots x_{H,W}

Here, x_{i,j} represents the number of cells that are edge-adjacent to cell (i, j).


Sample Input 1

4 5

Sample Output 1

2 3 3 3 2
3 4 4 4 3
3 4 4 4 3
2 3 3 3 2

The cells edge-adjacent to cell (1, 5) are cells (1, 4), (2, 5), for a total of two cells.

The cells edge-adjacent to cell (2, 3) are cells (1, 3), (2, 2), (2, 4), (3, 3), for a total of four cells.

The cells edge-adjacent to cell (4, 2) are cells (3, 2), (4, 1), (4, 3), for a total of three cells.


Sample Input 2

1 1

Sample Output 2

0

There are no cells edge-adjacent to cell (1, 1).


Sample Input 3

12 8

Sample Output 3

2 3 3 3 3 3 3 2
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
3 4 4 4 4 4 4 3
2 3 3 3 3 3 3 2
E - Select Mul

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

配点 : 300 点

問題文

整数 N が与えられます。N の各桁の数字を取り出して並べ(並べる順序は好きに変えてよい)、2 つの正整数に分離することを考えましょう。

例えば、123 という整数に対しては以下の 6 通りの分離の仕方が考えられます。

  • 12 と 3
  • 21 と 3
  • 13 と 2
  • 31 と 2
  • 23 と 1
  • 32 と 1

なお、ここで分離されたあとの 2 整数に leading zero が含まれていてはなりません。例えば、101 という整数を 1 と 01 の 2 つに分離することはできません。また上述の「正整数に分離する」という条件より、101 を 11 と 0 の 2 つに分離することもできません。

適切に N を分離したとき、分離後の 2 数の積の最大値はいくらになりますか?

制約

  • N は 1 以上 10^9 以下の整数
  • N には 0 でない桁が 2 つ以上含まれる

入力

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

N

出力

分離後の 2 数の積の最大値を出力せよ。


入力例 1

123

出力例 1

63

問題文中にある通り、以下の 6 通りの分離の仕方が考えられます。

  • 12 と 3
  • 21 と 3
  • 13 と 2
  • 31 と 2
  • 23 と 1
  • 32 と 1

積はそれぞれ 36, 63, 26, 62, 23, 32 であり、この中の最大値は 63 です。


入力例 2

1010

出力例 2

100

考えられる分離の仕方は以下の 2 通りです。

  • 100 と 1
  • 10 と 10

いずれの場合にも積は 100 となります。


入力例 3

998244353

出力例 3

939337176

Score : 300 points

Problem Statement

You are given an integer N. Consider permuting the digits in N and separate them into two positive integers.

For example, for the integer 123, there are six ways to separate it, as follows:

  • 12 and 3,
  • 21 and 3,
  • 13 and 2,
  • 31 and 2,
  • 23 and 1,
  • 32 and 1.

Here, the two integers after separation must not contain leading zeros. For example, it is not allowed to separate the integer 101 into 1 and 01. Additionally, since the resulting integers must be positive, it is not allowed to separate 101 into 11 and 0, either.

What is the maximum possible product of the two resulting integers, obtained by the optimal separation?

Constraints

  • N is an integer between 1 and 10^9 (inclusive).
  • N contains two or more digits that are not 0.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible product of the two integers after separation.


Sample Input 1

123

Sample Output 1

63

As described in Problem Statement, there are six ways to separate it:

  • 12 and 3,
  • 21 and 3,
  • 13 and 2,
  • 31 and 2,
  • 23 and 1,
  • 32 and 1.

The products of these pairs, in this order, are 36, 63, 26, 62, 23, 32, with 63 being the maximum.


Sample Input 2

1010

Sample Output 2

100

There are two ways to separate it:

  • 100 and 1,
  • 10 and 10.

In either case, the product is 100.


Sample Input 3

998244353

Sample Output 3

939337176