C - Taro

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

AtCoder 王国では、長男に必ず「太郎」という名前を付けます。長男以外には「太郎」という名前は付けません。 長男とは、各家で生まれた男の子のうち最も早く生まれた者を指します。

AtCoder 王国には N 戸の家があり、M 人の赤子が生まれました。また、M 人の赤子が生まれる前には、N 戸のどの家も赤子が生まれたことはありませんでした。

赤子の情報が生まれの時系列順に与えられます。

i 番目に生まれた赤子は、A_i 番目の家で生まれ、B_i が M のとき男の子、F のとき女の子です。

M 人の赤子それぞれについて、付けられた名前が「太郎」か判定してください。

制約

  • 1\leq N,M\leq 100
  • 1\leq A_i\leq N
  • B_i は M または F
  • 入力される数値は全て整数

入力

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

N M
A_1 B_1
\vdots
A_M B_M

出力

M 行出力せよ。

i\ (1\leq i \leq M) 行目には、i 番目に生まれた赤子の名前が「太郎」ならば Yes を、そうでない場合 No を出力せよ。


入力例 1

2 4
1 M
1 M
2 F
2 M

出力例 1

Yes
No
No
Yes

1 番目に生まれた赤子は、家 1 で生まれた男の子のうち最も早く生まれた者なので「太郎」です。

一方、2 番目に生まれた赤子は、家 1 で生まれた男の子のうち最も早く生まれた者ではないので「太郎」ではありません。

3 番目に生まれた赤子は、女の子なので「太郎」ではありません。

4 番目に生まれた赤子は、家 2 で生まれた男の子のうち最も早く生まれた者なので「太郎」です。3 番目に生まれた赤子も家 2 で生まれていますが、男の子のうち最も早く生まれた者を「太郎」と名付けることに注意してください。


入力例 2

4 7
2 M
3 M
1 F
4 F
4 F
1 F
2 M

出力例 2

Yes
Yes
No
No
No
No
No

Score : 200 points

Problem Statement

In the Kingdom of AtCoder, the eldest son is always given the name Taro. No one else is given the name Taro. The eldest son is the earliest born male child in each family.

There are N families in the Kingdom, and M babies were born. Before the M babies were born, none of the N families had had any babies.

Information about the babies is given in chronological order of their birth.

The i-th baby born was born in family A_i, and the baby is male if B_i is M, and female if it is F.

Determine for each of the M babies whether the name given is Taro.

Constraints

  • 1\leq N,M\leq 100
  • 1\leq A_i\leq N
  • B_i is M or F.
  • All numbers 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 M lines.

The i-th line (1\leq i \leq M) should contain Yes if the name given to the i-th baby is Taro, and No otherwise.


Sample Input 1

2 4
1 M
1 M
2 F
2 M

Sample Output 1

Yes
No
No
Yes

The first baby is the earliest born boy in family 1, so he is named Taro.

The second baby is not the earliest born boy in family 1, so he is not named Taro.

The third baby is a girl, so she is not named Taro.

The fourth baby is the earliest born boy in family 2, so he is named Taro. Note that the third baby is also born in family 2, but it is the earliest born boy who is named Taro.


Sample Input 2

4 7
2 M
3 M
1 F
4 F
4 F
1 F
2 M

Sample Output 2

Yes
Yes
No
No
No
No
No
D - Perfect

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

N 人の人が、M 問からなるプログラミングコンテストに参加しました。
参加者は人 1, 人 2, \ldots, 人 N と番号づけられており、問題は問題 1, 問題 2, \ldots, 問題 M と番号づけられています。

このコンテストでは K 個のイベントが順番に起き、i 番目 (1\leq i\leq K) のイベントでは次のことが起きました。

  • 人 A_i が問題 B_i に正解した。

同じイベントが 2 回以上起きることはありません。 また、この K 個のイベント以外に誰かがどれかの問題に正解することはありません。

すべての問題に正解した人の番号を全員出力してください。
そのような人が複数いる場合は、すべての問題に正解したタイミングが早い順に出力してください。

制約

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • K \geq 1
  • 1 \leq A_i\leq N
  • 1 \leq B_i\leq M
  • i\neq j ならば (A_i,B_i)\neq (A_j,B_j)
  • 入力はすべて整数

入力

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

N M K
A_1 B_1
A_2 B_2
\vdots
A_K B_K

出力

すべての問題に正解した人の番号を、すべての問題に正解したタイミングが早い順に空白区切りで一行に出力せよ。
すべての問題に正解した人がいないならば、何も出力しないようにせよ。


入力例 1

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

出力例 1

3 1

コンテストでは次のことが順に起きました。

  • 人 1 が問題 1 に正解した。人 1 はこれまでに、問題 1 のみに正解した。
  • 人 3 が問題 2 に正解した。人 3 はこれまでに、問題 2 のみに正解した。
  • 人 2 が問題 1 に正解した。人 2 はこれまでに、問題 1 のみに正解した。
  • 人 3 が問題 1 に正解した。人 3 はこれまでに、問題 1,2 に正解した。よって、この時点で人 3 はすべての問題に正解した。
  • 人 1 が問題 2 に正解した。人 1 はこれまでに、問題 1,2 に正解した。よって、この時点で人 1 はすべての問題に正解した。

よって、すべての問題に正解したのは人 1,3 であり、すべての問題に正解したタイミングは人 3 の方が早いです。
よって、3,1 をこの順に空白区切りで出力します。


入力例 2

2 2 2
1 1
2 2

出力例 2


すべての問題に正解した人がいない場合は、何も出力しないでください。

Score : 200 points

Problem Statement

N people participated in a programming contest consisting of M problems.
The participants are numbered person 1, person 2, \ldots, person N, and the problems are numbered problem 1, problem 2, \ldots, problem M.

In this contest, K events occurred in order; in the i-th event (1\leq i\leq K), the following happened:

  • Person A_i solved problem B_i.

The same event does not occur two or more times. Also, apart from these K events, nobody solves any problem.

Output the numbers of all people who solved all problems.
If there are multiple such people, output them in ascending order of the time at which they solved all problems.

Constraints

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • K \geq 1
  • 1 \leq A_i \leq N
  • 1 \leq B_i \leq M
  • If i\neq j then (A_i,B_i)\neq (A_j,B_j).
  • All input values are integers.

Input

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

N M K
A_1 B_1
A_2 B_2
\vdots
A_K B_K

Output

Output, on one line and separated by spaces, the numbers of all people who solved all problems, in ascending order of the time at which they solved all problems. If there is no person who solved all problems, output nothing.


Sample Input 1

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

Sample Output 1

3 1

In the contest, the following happened in order.

  • Person 1 solved problem 1. So far, person 1 has solved only problem 1.
  • Person 3 solved problem 2. So far, person 3 has solved only problem 2.
  • Person 2 solved problem 1. So far, person 2 has solved only problem 1.
  • Person 3 solved problem 1. So far, person 3 has solved problems 1,2. Thus, at this point person 3 has solved all problems.
  • Person 1 solved problem 2. So far, person 1 has solved problems 1,2. Thus, at this point person 1 has solved all problems.

Thus, the people who solved all problems are persons 1,3, and the one who solved all problems earlier is person 3. Thus, output 3,1 in this order, separated by spaces.


Sample Input 2

2 2 2
1 1
2 2

Sample Output 2


If there is no person who solved all problems, output nothing.

E - Lining Up 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

人 1, 人 2,\ldots, 人 N の N 人が一列に並んでいます。

並び方の情報が長さ N の数列 A=(A _ 1,A _ 2,\ldots,A _ N) として与えられます。

A _ i\ (1\leq i\leq N) は次のような情報を表しています。

  • A _ i=-1 のとき、人 i は先頭に並んでいる。
  • A _ i\neq -1 のとき、人 i は人 A _ i のすぐ後ろに並んでいる。

列に並んでいる人の番号を先頭から順番に出力してください。

制約

  • 1\leq N\leq3\times10 ^ 5
  • A _ i=-1 もしくは 1\leq A _ i\leq N\ (1\leq i\leq N)
  • 情報と矛盾しないような N 人の並び方がただ 1 通り存在する
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \ldots A _ N

出力

人 s _ 1, 人 s _ 2,\ldots, 人 s _ N がこの順に列に並んでいるとき、s _ 1,s _ 2,\ldots,s _ N をこの順に空白を区切りとして出力せよ。


入力例 1

6
4 1 -1 5 3 2

出力例 1

3 5 4 1 2 6

先頭から、人 3, 人 5, 人 4, 人 1, 人 2, 人 6 がこの順に列に並んでいるとき、与えられた情報と一致しています。

実際、

  • 人 1 は人 4 のすぐ後ろに並んでいます。
  • 人 2 は人 1 のすぐ後ろに並んでいます。
  • 人 3 は先頭に並んでいます。
  • 人 4 は人 5 のすぐ後ろに並んでいます。
  • 人 5 は人 3 のすぐ後ろに並んでいます。
  • 人 6 は人 2 のすぐ後ろに並んでいます。

となり、与えられた情報と一致していることが確認できます。

よって、3,5,4,1,2,6 をこの順に空白区切りで出力してください。


入力例 2

10
-1 1 2 3 4 5 6 7 8 9

出力例 2

1 2 3 4 5 6 7 8 9 10

入力例 3

30
3 25 20 6 18 12 26 1 29 -1 21 17 23 9 8 30 10 15 22 27 4 13 5 11 16 24 28 2 19 7

出力例 3

10 17 12 6 4 21 11 24 26 7 30 16 25 2 28 27 20 3 1 8 15 18 5 23 13 22 19 29 9 14

Score: 300 points

Problem Statement

There are N people standing in a line: person 1, person 2, \ldots, person N.

You are given the arrangement of the people as a sequence A=(A _ 1,A _ 2,\ldots,A _ N) of length N.

A _ i\ (1\leq i\leq N) represents the following information:

  • if A _ i=-1, person i is at the front of the line;
  • if A _ i\neq -1, person i is right behind person A _ i.

Print the people's numbers in the line from front to back.

Constraints

  • 1\leq N\leq3\times10 ^ 5
  • A _ i=-1 or 1\leq A _ i\leq N\ (1\leq i\leq N)
  • There is exactly one way to arrange the N people consistent with the information given.
  • All input values are integers.

Input

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

N
A _ 1 A _ 2 \ldots A _ N

Output

If person s _ 1, person s _ 2, \ldots, person s _ N are standing in the line in this order, print s _ 1, s _ 2, \ldots, and s _ N in this order, separated by spaces.


Sample Input 1

6
4 1 -1 5 3 2

Sample Output 1

3 5 4 1 2 6

If person 3, person 5, person 4, person 1, person 2, and person 6 stand in line in this order from front to back, the arrangement matches the given information.

Indeed, it can be seen that:

  • person 1 is standing right behind person 4,
  • person 2 is standing right behind person 1,
  • person 3 is at the front of the line,
  • person 4 is standing right behind person 5,
  • person 5 is standing right behind person 3, and
  • person 6 is standing right behind person 2.

Thus, print 3, 5, 4, 1, 2, and 6 in this order, separated by spaces.


Sample Input 2

10
-1 1 2 3 4 5 6 7 8 9

Sample Output 2

1 2 3 4 5 6 7 8 9 10

Sample Input 3

30
3 25 20 6 18 12 26 1 29 -1 21 17 23 9 8 30 10 15 22 27 4 13 5 11 16 24 28 2 19 7

Sample Output 3

10 17 12 6 4 21 11 24 26 7 30 16 25 2 28 27 20 3 1 8 15 18 5 23 13 22 19 29 9 14
F - Peak

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

高橋くんは数直線上に N 個のプレゼントを置きました。そのうち i 個目のプレゼントは座標 A_i に置かれました。

あなたは数直線上の長さ M の半開区間 [x,x+M) を選び、そこに含まれるプレゼントを全て獲得します。
より詳しくは、以下の手順でプレゼントを獲得します。

  • まず、実数 x をひとつ選択する。
  • その後、プレゼントのうち置かれている座標が x \le A_i < x+M を満たすものを全て獲得する。

最大でいくつのプレゼントを獲得することができますか?

制約

  • 入力は全て整数
  • 1 \le N \le 3 \times 10^5
  • 1 \le M \le 10^9
  • 0 \le A_i \le 10^9

入力

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

N M
A_1 A_2 \dots A_N

出力

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


入力例 1

8 6
2 3 5 7 11 13 17 19

出力例 1

4

例えば、半開区間 [1.5,7.5) を指定します。
このとき、座標 2,3,5,7 にある 4 つのプレゼントを全て獲得することができ、これが獲得可能な最大の個数です。


入力例 2

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

出力例 2

2

同一の座標に複数のプレゼントが置いてあることもあります。


入力例 3

10 998244353
100000007 0 1755647 998244353 495 1000000000 1755648 503 1755649 998244853

出力例 3

7

Score : 300 points

Problem Statement

Takahashi has placed N gifts on a number line. The i-th gift is placed at coordinate A_i.

You will choose a half-open interval [x,x+M) of length M on the number line and acquire all the gifts included in it.
More specifically, you acquire gifts according to the following procedure.

  • First, choose one real number x.
  • Then, acquire all the gifts whose coordinates satisfy x \le A_i < x+M.

What is the maximum number of gifts you can acquire?

Constraints

  • All input values are integers.
  • 1 \le N \le 3 \times 10^5
  • 1 \le M \le 10^9
  • 0 \le A_i \le 10^9

Input

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

N M
A_1 A_2 \dots A_N

Output

Print the answer as an integer.


Sample Input 1

8 6
2 3 5 7 11 13 17 19

Sample Output 1

4

For example, specify the half-open interval [1.5,7.5).
In this case, you can acquire the four gifts at coordinates 2,3,5,7, the maximum number of gifts that can be acquired.


Sample Input 2

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

Sample Output 2

2

There may be multiple gifts at the same coordinate.


Sample Input 3

10 998244353
100000007 0 1755647 998244353 495 1000000000 1755648 503 1755649 998244853

Sample Output 3

7
G - Match or Not

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

英小文字と ? からなる文字列 S,T が与えられます。ここで、|S| \gt |T| が成り立ちます(文字列 X に対し、 |X| で X の長さを表します)。

また、|X|=|Y| を満たす文字列 X,Y は、次の条件を満たすとき及びそのときに限りマッチするといいます。

  • X,Y に含まれる ? をそれぞれ独立に好きな英小文字に置き換えることで X と Y を一致させることができる

x=0,1,\ldots,|T| に対して次の問題を解いてください。

  • S の先頭の x 文字と末尾の |T|-x 文字を順番を保ったまま連結することで得られる長さ |T| の文字列を S' とする。S' と T がマッチするならば Yes と、そうでなければ No と出力せよ。

制約

  • S,T は英小文字と ? からなる文字列
  • 1 \leq |T| \lt |S| \leq 3 \times 10^5

入力

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

S
T

出力

|T|+1 行出力せよ。
i 行目には x=i-1 に対する出力をせよ。


入力例 1

a?c
b?

出力例 1

Yes
No
No

x=0 の場合、S' は ?c となります。ここで、S' の 1 文字目の ? を b に、T の 2 文字目の ? を c に置き換えることで S' と T を一致させることができるため、S' と T はマッチします。このため、1 行目の出力は Yes です。
x=1,2 の場合は S' はそれぞれ ac、a? であり、T とマッチしません。このため、2,3 行目の出力は No です。


入力例 2

atcoder
?????

出力例 2

Yes
Yes
Yes
Yes
Yes
Yes

入力例 3

beginner
contest

出力例 3

No
No
No
No
No
No
No
No

Score : 400 points

Problem Statement

You are given strings S and T consisting of lowercase English letters and ?. Here, |S| \gt |T| holds (for a string X, |X| denotes the length of X).

Two strings X and Y such that |X|=|Y| is said to match if and only if:

  • one can make X equal Y by replacing each ? in X and Y with any English letter independently.

Solve the following problem for each x=0,1,\ldots,|T|:

  • Let S' be the string of length |T| obtained by concatenating the first x characters and the last (|T|-x) characters of S without changing the order. Print Yes if S' and T match, and No otherwise.

Constraints

  • S and T are strings consisting of lowercase English letters and ?.
  • 1 \leq |T| \lt |S| \leq 3 \times 10^5

Input

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

S
T

Output

Print (|T|+1) lines.
The i-th line should contain the answer for x=i-1.


Sample Input 1

a?c
b?

Sample Output 1

Yes
No
No

When x=0, S' equals ?c. Here, we can replace the 1-st character of S', ?, with b and the 2-nd character of T, ?, with c to make S' equal T, so S' and T match. Thus, Yes should be printed in the first line.
When x=1 and 2, respectively, S' is ac and a?, neither of which matches with T. Thus, No should be printed in the second and third lines.


Sample Input 2

atcoder
?????

Sample Output 2

Yes
Yes
Yes
Yes
Yes
Yes

Sample Input 3

beginner
contest

Sample Output 3

No
No
No
No
No
No
No
No