C - Vertical Reading

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

配点 : 200

問題文

英小文字からなる文字列 ST が与えられます。

以下の条件を満たす 1 \leq c \leq w < |S| となる整数の組 cw が存在するか判定してください。ただし、 |S| は文字列 S の長さを表します。ここで、w|S| 未満である必要があることに注意してください。

  • S を先頭から順に w 文字毎に区切ったとき、長さが c 以上の文字列の c 文字目を順番に連結した文字列が T と一致する

制約

  • ST は英小文字からなる文字列
  • 1 \leq |T| \leq |S| \leq 100

入力

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

S T

出力

条件を満たすような 1 \leq c \leq w < |S| となる整数の組 cw が存在する場合は Yes を、存在しない場合は No を出力せよ。


入力例 1

atcoder toe

出力例 1

Yes

S2 文字毎に区切ると以下のようになります。

at
co
de
r

区切った後、 2 文字以上の文字列の 2 文字目を取り出し連結させたときの文字列は、 toe となり T と一致します。よって、 Yes を出力します。


入力例 2

beginner r

出力例 2

No

w=|S| であることはないため、条件を満たすような 1 \leq c \leq w < |S| となる整数の組 cw は存在しません。よって、 No を出力します。


入力例 3

verticalreading agh

出力例 3

No

Score : 200 points

Problem Statement

You are given two strings S and T consisting of lowercase English letters.

Determine if there exists a pair of integers c and w such that 1 \leq c \leq w < |S| and the following condition is satisfied. Here, |S| denotes the length of the string S. Note that w must be less than |S|.

  • If S is split at every w characters from the beginning, the concatenation of the c-th characters of the substrings of length at least c in order equals T.

Constraints

  • S and T are strings consisting of lowercase English letters.
  • 1 \leq |T| \leq |S| \leq 100

Input

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

S T

Output

Print Yes if there exists a pair of integers c and w such that 1 \leq c \leq w < |S| and the condition is satisfied, and No otherwise.


Sample Input 1

atcoder toe

Sample Output 1

Yes

If S is split at every two characters, it looks like this:

at
co
de
r

Then, the concatenation of the 2nd characters of the substrings of length at least 2 is toe, which equals T. Thus, print Yes.


Sample Input 2

beginner r

Sample Output 2

No

w=|S| is not allowed, and no pair of integers 1 \leq c \leq w < |S| satisfies the condition. Thus, print No.


Sample Input 3

verticalreading agh

Sample Output 3

No
D - Adjacency List

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

配点 : 200

問題文

1, \dots, N と番号付けられた N 個の都市と、都市間を結ぶ M 本の道路があります。
i \, (1 \leq i \leq M) 番目の道路は都市 A_i と都市 B_i を結んでいます。

以下の指示に従い、N 行にわたって出力してください。

  • 都市 i \, (1 \leq i \leq N) と道路で直接結ばれた都市が d_i 個あるとし、それらを昇順に都市 a_{i, 1}, \dots, a_{i, d_i} とおく。
  • i \, (1 \leq i \leq N) 行目には、d_i + 1 個の整数 d_i, a_{i, 1}, \dots, a_{i, d_i} を、この順番で空白区切りで出力せよ。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq M \leq 10^5
  • 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
  • (i \neq j) ならば (A_i, B_i) \neq (A_j, B_j)
  • 入力される値は全て整数

入力

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

N M
A_1 B_1
\vdots
A_M B_M

出力

問題文の指示に従い、N 行にわたって出力せよ。


入力例 1

6 6
3 6
1 3
5 6
2 5
1 2
1 6

出力例 1

3 2 3 6
2 1 5
2 1 6
0
2 2 6
3 1 3 5

都市 1 と道路で直接結ばれているのは都市 2, 3, 6 です。よって、d_1 = 3, a_{1, 1} = 2, a_{1, 2} = 3, a_{1, 3} = 6 であるので、1 行目には 3, 2, 3, 6 をこの順番で空白区切りで出力します。

a_{i, 1}, \dots, a_{i, d_i} は昇順に並んでいなければならないことに注意してください。例えば、1 行目に 3, 3, 2, 6 をこの順番で出力した場合、不正解となります。


入力例 2

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

出力例 2

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

Score : 200 points

Problem Statement

There are N cities numbered 1, \dots, N, and M roads connecting cities.
The i-th road (1 \leq i \leq M) connects city A_i and city B_i.

Print N lines as follows.

  • Let d_i be the number of cities directly connected to city i \, (1 \leq i \leq N), and those cities be city a_{i, 1}, \dots, city a_{i, d_i}, in ascending order.
  • The i-th line (1 \leq i \leq N) should contain d_i + 1 integers d_i, a_{i, 1}, \dots, a_{i, d_i} in this order, separated by spaces.

Constraints

  • 2 \leq N \leq 10^5
  • 1 \leq M \leq 10^5
  • 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
  • (A_i, B_i) \neq (A_j, B_j) if (i \neq j).
  • All values in the input are integers.

Input

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

N M
A_1 B_1
\vdots
A_M B_M

Output

Print N lines as specified in the Problem Statement.


Sample Input 1

6 6
3 6
1 3
5 6
2 5
1 2
1 6

Sample Output 1

3 2 3 6
2 1 5
2 1 6
0
2 2 6
3 1 3 5

The cities directly connected to city 1 are city 2, city 3, and city 6. Thus, we have d_1 = 3, a_{1, 1} = 2, a_{1, 2} = 3, a_{1, 3} = 6, so you should print 3, 2, 3, 6 in the first line in this order, separated by spaces.

Note that a_{i, 1}, \dots, a_{i, d_i} must be in ascending order. For instance, it is unacceptable to print 3, 3, 2, 6 in the first line in this order.


Sample Input 2

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

Sample Output 2

4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4
E - Socks

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

配点 : 300

問題文

N 枚の靴下があります。i 枚目の靴下の色は A_i です。

あなたは以下の操作をできるだけ多い回数行いたいです。最大で何回行うことができますか?

  • まだペアになっていない靴下の中から同じ色の靴下を 2 枚選んでペアにする。

制約

  • 1\leq N \leq 5\times 10^5
  • 1\leq A_i \leq 10^9
  • 入力は全て整数

入力

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

N
A_1 A_2 \dots A_N

出力

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


入力例 1

6
4 1 7 4 1 4

出力例 1

2

以下のようにして、2 回の操作を行うことができます。

  • 色が 1 である靴下を 2 枚選んでペアにする。
  • 色が 4 である靴下を 2 枚選んでペアにする。

このとき、色が 4 である靴下と 7 である靴下が 1 枚ずつ残るため、これ以上操作はできません。 また、どのように操作をしても 3 回以上操作を行うことはできないため、2 を出力します。


入力例 2

1
158260522

出力例 2

0

入力例 3

10
295 2 29 295 29 2 29 295 2 29

出力例 3

4

Score : 300 points

Problem Statement

You have N socks. The color of the i-th sock is A_i.

You want to perform the following operation as many times as possible. How many times can it be performed at most?

  • Choose two same-colored socks that are not paired yet, and pair them.

Constraints

  • 1\leq N \leq 5\times 10^5
  • 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:

N
A_1 A_2 \dots A_N

Output

Print an integer representing the answer.


Sample Input 1

6
4 1 7 4 1 4

Sample Output 1

2

You can do the operation twice as follows.

  • Choose two socks with the color 1 and pair them.
  • Choose two socks with the color 4 and pair them.

Then, you will be left with one sock with the color 4 and another with the color 7, so you can no longer do the operation. There is no way to do the operation three or more times, so you should print 2.


Sample Input 2

1
158260522

Sample Output 2

0

Sample Input 3

10
295 2 29 295 29 2 29 295 2 29

Sample Output 3

4
F - 321-like Searcher

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

配点 : 300

問題文

以下の条件を満たす正整数 x321-like Number と呼びます。 この定義は A 問題と同様です。

  • x の各桁を上から見ると狭義単調減少になっている。
  • すなわち、xd 桁の整数だとすると、 1 \le i < d を満たす全ての整数 i について以下の条件を満たす。
    • ( x の上から i 桁目 ) > ( x の上から i+1 桁目 )

なお、 1 桁の正整数は必ず 321-like Number であることに注意してください。

例えば、 321,96410,1 は 321-like Number ですが、 123,2109,86411 は 321-like Number ではありません。

K 番目に小さい 321-like Number を求めてください。

制約

  • 入力は全て整数
  • 1 \le K
  • 321-like Number は K 個以上存在する

入力

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

K

出力

K 番目に小さい 321-like Number を整数として出力せよ。


入力例 1

15

出力例 1

32

321-like Number は小さいものから順に (1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots) です。
このうち 15 番目に小さいものは 32 です。


入力例 2

321

出力例 2

9610

入力例 3

777

出力例 3

983210

Score : 300 points

Problem Statement

A positive integer x is called a 321-like Number when it satisfies the following condition. This definition is the same as the one in Problem A.

  • The digits of x are strictly decreasing from top to bottom.
  • In other words, if x has d digits, it satisfies the following for every integer i such that 1 \le i < d:
    • (the i-th digit from the top of x) > (the (i+1)-th digit from the top of x).

Note that all one-digit positive integers are 321-like Numbers.

For example, 321, 96410, and 1 are 321-like Numbers, but 123, 2109, and 86411 are not.

Find the K-th smallest 321-like Number.

Constraints

  • All input values are integers.
  • 1 \le K
  • At least K 321-like Numbers exist.

Input

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

K

Output

Print the K-th smallest 321-like Number as an integer.


Sample Input 1

15

Sample Output 1

32

The 321-like Numbers are (1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots) from smallest to largest.
The 15-th smallest of them is 32.


Sample Input 2

321

Sample Output 2

9610

Sample Input 3

777

Sample Output 3

983210
G - Attend Many Events

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

配点 : 450

問題文

AtCoder Land には N 個の地点と M 個の道があります。i 個目の道は地点 a_ib_i を双方向に結び、通過するのに d_i 分かかります。

これから、AtCoder Land で K 個のイベントが開催されます。i 個目のイベントに参加するには、時刻 t_i 分に地点 c_i にいる必要があります。イベントにかかる時間は 0 分です。

あなたは、時刻 0 分に地点 1 にいます。適切に行動したとき、最大で何個のイベントに参加できるか求めてください。

制約

  • 1 \leq N \leq 1000
  • 0 \leq M \leq 1000
  • 1 \leq K \leq 1000
  • 1 \leq a_i < b_i \leq N
  • i \neq j なら (a_i, b_i) \neq (a_j, b_j)
  • 1 \leq d_i \leq 10^9
  • 1 \leq c_i \leq N
  • 1 \leq t_i \leq 10^9
  • i \neq j なら (c_i,t_i) \neq (c_j,t_j)
  • 入力はすべて整数

入力

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

N M K
a_1 b_1 d_1
a_2 b_2 d_2
\vdots
a_M b_M d_M
c_1 t_1
c_2 t_2
\vdots
c_K t_K

出力

答えを出力せよ。


入力例 1

3 3 3
1 2 1
1 3 3
2 3 7
1 8
2 2
3 7

出力例 1

2

たとえば、次のように行動することで、2 つのイベントに参加することができます。

  • はじめ、時刻 0 分に地点 1 にいる
  • 1 を通って時刻 1 分に地点 2 に到着する
  • 時刻 2 分に地点 2 でイベント 2 に参加する
  • 1 を通って時刻 3 分に地点 1 に到着する
  • 2 を通って時刻 6 分に地点 3 に到着する
  • 時刻 7 分に地点 3 でイベント 3 に参加する

3 つ以上のイベントに参加することはできないので、答えは 2 です。


入力例 2

1 0 2
1 1
1 100

出力例 2

2

道が存在しないため、地点 1 から動くことはできませんが、地点 1 で開催される 2 つのイベントに参加することができます。


入力例 3

5 8 10
1 2 149622151
1 4 177783960
4 5 118947237
1 3 33222944
1 5 295060863
3 5 110881471
2 3 34104208
3 4 273071547
2 650287940
4 839296263
3 462224593
1 492601449
4 384836991
1 191890310
5 576823355
3 782177068
3 404011431
1 818008580

出力例 3

6