A - 9x9

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

1 文字目が数字、2 文字目が文字 x、3 文字目が数字であるような 3 文字の文字列 S が与えられます。

S の 2 つの数の積を求めてください。

制約

  • S は 1 文字目が 1 以上 9 以下の整数、2 文字目が文字 x、3 文字目が 1 以上 9 以下の整数であるような 3 文字の文字列

入力

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

S

出力

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


入力例 1

3x8

出力例 1

24

3 \times 8 = 24 より、24 を出力します。


入力例 2

9x9

出力例 2

81

9 \times 9 = 81 より、81 を出力します。

Score : 100 points

Problem Statement

You are given a 3-character string S, where the first character is a digit, the second character is the character x, and the third character is a digit.

Find the product of the two numbers in S.

Constraints

  • S is a 3-character string where the first character is an integer between 1 and 9, inclusive, the second character is the character x, and the third character is an integer between 1 and 9, inclusive.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

3x8

Sample Output 1

24

From 3 \times 8 = 24, print 24.


Sample Input 2

9x9

Sample Output 2

81

From 9 \times 9 = 81, print 81.

B - On and Off

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

高橋君は、毎日 S 時 0 分に部屋の電気をつけ、毎日 T 時 0 分に消します。
電気をつけている間に日付が変わることもあります。

X 時 30 分に部屋の電気がついているかどうか判定してください。

制約

  • 0 \leq S, T, X \leq 23
  • S \neq T
  • 入力は全て整数である。

入力

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

S T X

出力

X 時 30 分に部屋の電気がついているならば Yes と、そうでなければ No と出力せよ。


入力例 1

7 20 12

出力例 1

Yes

部屋の電気がついているのは 7 時 0 分から 20 時 0 分までの間です。12 時 30 分には電気がついているので、Yes と出力します。


入力例 2

20 7 12

出力例 2

No

部屋の電気がついているのは 0 時 0 分から 7 時 0 分までの間と、20 時 0 分から(次の日の)0 時 0 分までの間です。 12 時 30 分には電気がついていないので、No と出力します。


入力例 3

23 0 23

出力例 3

Yes

Score : 100 points

Problem Statement

Takahashi turns on the light of his room at S o'clock (on the 24-hour clock) every day and turns it off at T o'clock every day.
The date may change while the light is on.

Determine whether the light is on at 30 minutes past X o'clock.

Constraints

  • 0 \leq S, T, X \leq 23
  • S \neq T
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

S T X

Output

If the light is on at 30 minutes past X o'clock, print Yes; otherwise, print No.


Sample Input 1

7 20 12

Sample Output 1

Yes

The light is on between 7 o'clock and 20 o'clock. At 30 minutes past 12 o'clock, it is on, so we print Yes.


Sample Input 2

20 7 12

Sample Output 2

No

The light is on between 0 o'clock and 7 o'clock, and between 20 o'clock and 0 o'clock (on the next day). At 30 minutes past 12 o'clock, it is off, so we print No.


Sample Input 3

23 0 23

Sample Output 3

Yes
C - Practical Computing

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

以下のような N 個の整数列 A_0,\ldots,A_{N-1} を求めてください。

  • 各 i (0\leq i \leq N-1) について、A_i の長さは i+1 である。
  • 各 i,j (0\leq i \leq N-1, 0 \leq j \leq i) について、A_i の j+1 番目の値 a_{i,j} は次のように定められる。

    • j=0 または j=i の時、a_{i,j}=1
    • それ以外の時、a_{i,j} = a_{i-1,j-1} + a_{i-1,j}

制約

  • 1 \leq N \leq 30
  • N は整数

入力

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

N

出力

N 行出力せよ。 i 行目には A_{i-1} の値を順に空白区切りで出力せよ。


入力例 1

3

出力例 1

1
1 1
1 2 1

入力例 2

10

出力例 2

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1

Score : 200 points

Problem Statement

Find the N integer sequences A_0,\ldots,A_{N-1} defined as follows.

  • For each i (0\leq i \leq N-1), the length of A_i is i+1.
  • For each i and j (0\leq i \leq N-1, 0 \leq j \leq i), the (j+1)-th term of A_i, denoted by a_{i,j}, is defined as follows.
    • a_{i,j}=1, if j=0 or j=i.
    • a_{i,j} = a_{i-1,j-1} + a_{i-1,j}, otherwise.

Constraints

  • 1 \leq N \leq 30
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print N lines. The i-th line should contain the terms of A_{i-1} separated by spaces.


Sample Input 1

3

Sample Output 1

1
1 1
1 2 1

Sample Input 2

10

Sample Output 2

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
D - CTZ

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

正の整数 X に対して、X を 2 進表記したときに 末尾 に連続する 0 の個数(の最大値)を \text{ctz}(X) で表します。
ただし、X を 2 進表記したとき末尾が 1 ならば \text{ctz}(X)=0 です。

正の整数 N が与えられるので、\text{ctz}(N) を出力してください。

制約

  • 1\leq N\leq 10^9
  • N は整数

入力

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

N

出力

\text{ctz}(N) を出力せよ。


入力例 1

2024

出力例 1

3

2024 を 2 進表記すると 11111101000 であり、末尾から 0 が 3 個連続しているため、\text{ctz}(2024)=3 です。
よって、3 を出力します。


入力例 2

18

出力例 2

1

18 を 2 進表記すると 10010 であるため、\text{ctz}(18)=1 です。
0 は末尾から連続する必要があることに注意してください。


入力例 3

5

出力例 3

0

Score: 200 points

Problem Statement

For a positive integer X, let \text{ctz}(X) be the (maximal) number of consecutive zeros at the end of the binary notation of X.
If the binary notation of X ends with a 1, then \text{ctz}(X)=0.

You are given a positive integer N. Print \text{ctz}(N).

Constraints

  • 1\leq N\leq 10^9
  • N is an integer.

Input

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

N

Output

Print \text{ctz}(N).


Sample Input 1

2024

Sample Output 1

3

2024 is 11111101000 in binary, with three consecutive 0s from the end, so \text{ctz}(2024)=3.
Thus, print 3.


Sample Input 2

18

Sample Output 2

1

18 is 10010 in binary, so \text{ctz}(18)=1.
Note that we count the trailing zeros.


Sample Input 3

5

Sample Output 3

0
E - Pigeonhole Query

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

N 匹の鳩がおり、 1 から N までの番号がつけられています。また、 N 個の巣があり、 1 から N までの番号がつけられています。はじめ、鳩 i は巣 i にいます (1\leq i\leq N)。

Q 個のクエリが与えられるので順に処理してください。 クエリは 2 種類あり、以下のいずれかの形式で与えられます。

  • 1 P H : 鳩 P を巣 H に移動させる。
  • 2 : 複数の鳩がいる巣の個数を出力する。

制約

  • 2\leq N\leq 10^6
  • 1\leq Q\leq 3\times 10^5
  • 1\leq P,H\leq N
  • 1 つ目の形式のクエリについて、鳩 P は移動する前に巣 H にいない
  • 入力は全て整数

入力

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

N Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

各クエリは以下の 2 種類のいずれかの形式で与えられる。

1 P H
2

出力

問題文の指示に従ってクエリへの答えを改行区切りで出力せよ。


入力例 1

4 7
2
1 1 2
2
1 3 2
2
1 3 4
2

出力例 1

0
1
1
2

初め、鳩 1,2,3,4 はそれぞれ巣 1,2,3,4 にいます。

  • 1 つ目のクエリについて、巣 1,2,3,4 にはそれぞれ 1,1,1,1 匹います。鳩が複数いる巣は存在しないので 0 を出力します。
  • 2 つ目のクエリについて、鳩 1 を巣 2 に移動します。
  • 3 つ目のクエリについて、巣 1,2,3,4 にはそれぞれ 0,2,1,1 匹います。鳩が複数いる巣は巣 2 の 1 つなので 1 を出力します。
  • 4 つ目のクエリについて、鳩 3 を巣 2 に移動します。
  • 5 つ目のクエリについて、巣 1,2,3,4 にはそれぞれ 0,3,0,1 匹います。鳩が複数いる巣は巣 2 の 1 つなので 1 を出力します。
  • 6 つ目のクエリについて、鳩 3 を巣 4 に移動します。
  • 7 つ目のクエリについて、巣 1,2,3,4 にはそれぞれ 0,2,0,2 匹います。鳩が複数いる巣は巣 2,4 の 2 つなので 2 を出力します。

入力例 2

5 10
2
1 4 3
1 4 5
2
1 3 1
2
1 2 3
1 2 5
1 1 3
2

出力例 2

0
1
2
1

Score : 300 points

Problem Statement

There are N pigeons numbered from 1 to N, and there are N nests numbered from 1 to N. Initially, pigeon i is in nest i for 1\leq i\leq N.

You are given Q queries, which you must process in order. There are two types of queries, each given in one of the following formats:

  • 1 P H : Move pigeon P to nest H.
  • 2 : Output the number of nests that contain more than one pigeon.

Constraints

  • 2 \leq N \leq 10^6
  • 1 \leq Q \leq 3\times 10^5
  • 1 \leq P, H \leq N
  • For a query of the first type, pigeon P is not in nest H before the move.
  • All input values are integers.

Input

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

N Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

Each query is given in one of the following two formats:

1 P H
2

Output

Print the answer to each query on a new line according to the instructions in the problem statement.


Sample Input 1

4 7
2
1 1 2
2
1 3 2
2
1 3 4
2

Sample Output 1

0
1
1
2

Initially, pigeons 1,2,3,4 are in nests 1,2,3,4, respectively.

  • For the 1st query, the counts of pigeons in nests 1,2,3,4 are 1,1,1,1. No nests contain multiple pigeons, output 0.
  • For the 2nd query, move pigeon 1 to nest 2.
  • For the 3rd query, the counts become 0,2,1,1, respectively. One nest (nest 2) contains multiple pigeons, so output 1.
  • For the 4th query, move pigeon 3 to nest 2.
  • For the 5th query, the counts become 0,3,0,1, respectively. One nest (nest 2) contains multiple pigeons, so output 1.
  • For the 6th query, move pigeon 3 to nest 4.
  • For the 7th query, the counts become 0,2,0,2, respectively. Two nests (nests 2 and 4) contain multiple pigeons, so output 2.

Sample Input 2

5 10
2
1 4 3
1 4 5
2
1 3 1
2
1 2 3
1 2 5
1 1 3
2

Sample Output 2

0
1
2
1