実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
整数 a, b, c が与えられます。b がこれらの整数の中央値であるかどうか判定してください。
制約
- 1 \leq a, b, c \leq 100
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
a b c
出力
b が与えられた整数の中央値であるならば Yes、そうでないならば No と出力せよ。
入力例 1
5 3 2
出力例 1
Yes
与えられた整数を小さい順に並べると 2, 3, 5 となり、b はこれらの整数の中央値です。
入力例 2
2 5 3
出力例 2
No
b は与えられた整数の中央値ではありません。
入力例 3
100 100 100
出力例 3
Yes
Score : 100 points
Problem Statement
Given integers a, b, and c, determine if b is the median of these integers.
Constraints
- 1 \leq a, b, c \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
a b c
Output
If b is the median of the given integers, then print Yes; otherwise, print No.
Sample Input 1
5 3 2
Sample Output 1
Yes
The given integers are 2, 3, 5 when sorted in ascending order, of which b is the median.
Sample Input 2
2 5 3
Sample Output 2
No
b is not the median of the given integers.
Sample Input 3
100 100 100
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
正整数 N, M が与えられます。
M の値が 0 でない間以下の操作を繰り返すとき、操作を行う回数を求めてください。
- N を M で割った余りを x とする。M の値を x で置き換える。
なお、この操作を有限回行うことにより M = 0 になることが証明できます。
制約
- 1 \leq N, M \leq 1000
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
答えを出力せよ。
入力例 1
8 5
出力例 1
3
はじめ、N = 8, M = 5 です。
8 を 5 で割った余りは 3 であるため、1 回操作を行うと M = 3 となります。
8 を 3 で割った余りは 2 であるため、2 回操作を行うと M = 2 となります。
8 を 2 で割った余りは 0 であるため、3 回操作を行うと M = 0 となります。
したがって、3 を答えとして出力します。
入力例 2
14 6
出力例 2
2
入力例 3
460 33
出力例 3
5
Score : 100 points
Problem Statement
You are given positive integers N and M.
If the following operation is repeated while the value of M is not 0, find the number of operations performed.
- Let x be the remainder when N is divided by M. Replace the value of M with x.
It can be proved that M becomes 0 after a finite number of operations.
Constraints
- 1 \leq N, M \leq 1000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Output the answer.
Sample Input 1
8 5
Sample Output 1
3
Initially, N = 8 and M = 5.
The remainder when 8 is divided by 5 is 3, so M = 3 after one operation.
The remainder when 8 is divided by 3 is 2, so M = 2 after two operations.
The remainder when 8 is divided by 2 is 0, so M = 0 after three operations.
Thus, output 3 as the answer.
Sample Input 2
14 6
Sample Output 2
2
Sample Input 3
460 33
Sample Output 3
5
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
AtCoder 国の公用語は、高橋語と青木語の 2 つの言語です。
高橋語と青木語は、どちらもその言語に含まれる単語を表記するのに英小文字の一部を使います。 高橋語では長さ N の文字列 S に含まれる文字のみを使い、青木語では長さ M の文字列 T に含まれる文字のみを使います。
AtCoder 国の公用語に含まれる Q 個の単語 w _ 1,w _ 2,\ldots,w _ Q が与えられます。 それぞれの単語について、その単語に含まれる文字からその単語が次のうちどれに該当するか判定してください。
- 高橋語の単語であることが確定する
- 青木語の単語であることが確定する
- どちらともいえない
制約
- 1\le N\le26
- 1\le M\le26
- S は英小文字からなる長さ N の文字列
- S に含まれる文字は先頭からアルファベット順で昇順に並んでいる
- S に含まれる文字はすべて異なる
- T は英小文字からなる長さ M の文字列
- T に含まれる文字は先頭からアルファベット順で昇順に並んでいる
- T に含まれる文字はすべて異なる
- 1\le Q\le100
- w _ i は英小文字からなる長さ 1 以上 100 以下の文字列 (1\le i\le Q)
- w _ i は高橋語か青木語のどちらかの単語 (1\le i\le Q)
- N,M,Q は整数
入力
入力は以下の形式で標準入力から与えられる。
N M S T Q w _ 1 w _ 2 \vdots w _ Q
出力
Q 行にわたって出力せよ。
i 行目には、w _ i が高橋語の単語であることが確定するなら Takahashi 、青木語の単語であることが確定するなら Aoki 、どちらとも確定しないなら Unknown と出力せよ。
入力例 1
6 5 ahikst aikot 5 asahi okita kiai hash it
出力例 1
Takahashi Aoki Unknown Takahashi Unknown
例えば、a, s, h, i はすべて高橋語で使われる文字で、h は青木語で使われる文字ではないので asahi は高橋語の単語であることが確定します。
よって、1 行目には Takahashi と出力してください。
i および t はどちらも高橋語でも青木語でも使われる文字なので it は高橋語の単語であるとも青木語の単語であるとも確定しません。
よって、5 行目には Unknown と出力してください。
入力例 2
7 6 ahiknst ahikos 5 kioki ohiki tashi nishi kashi
出力例 2
Aoki Aoki Takahashi Takahashi Unknown
o は高橋語で使われる文字ではないので、はじめ 2 つの単語は青木語の単語であることが確定します。
よって、1 行目と 2 行目には Aoki と出力してください。
t や n は青木語で使われる文字ではないので、続く 2 つの単語は高橋語の単語であることが確定します。
よって、3 行目と 4 行目には Takahashi と出力してください。
はじめ 4 つの単語については、末尾が shi なら高橋語、末尾が ki なら青木語という法則がありますが、k, a, s, h, i はいずれも高橋語と青木語の両方で使われる文字なので kashi がどちらの言語の単語であるかを使われている文字から確定させることはできません。
よって、5 行目には Unknown と出力してください。
入力例 3
13 11 defghiqsvwxyz acejmoqrtwx 15 qhsqzhd jcareec wwqxqew wxqxwex jxxrtwa trtqjxe sqyggse xxqwxew xewwxxw wwqxwex xqqxqwq qxxexxe teqeroc eeeqqee vxdevyy
出力例 3
Takahashi Aoki Unknown Unknown Aoki Aoki Takahashi Unknown Unknown Unknown Unknown Unknown Aoki Unknown Takahashi
Score : 200 points
Problem Statement
The AtCoder country has two official languages: Takahashi-go and Aoki-go.
Both Takahashi-go and Aoki-go use some lowercase English letters to write words in those languages. Takahashi-go uses only the characters contained in a string S of length N, and Aoki-go uses only the characters contained in a string T of length M.
You are given Q words w _ 1,w _ 2,\ldots,w _ Q that are in the official languages of the AtCoder country. For each word, determine which of the following applies based on the characters contained in that word:
- It is confirmed to be a word in Takahashi-go
- It is confirmed to be a word in Aoki-go
- Neither can be determined
Constraints
- 1\le N\le26
- 1\le M\le26
- S is a string of length N consisting of lowercase English letters.
- The characters in S are arranged in alphabetical order.
- All characters in S are distinct.
- T is a string of length M consisting of lowercase English letters.
- The characters in T are arranged in alphabetical order.
- All characters in T are distinct.
- 1\le Q\le100
- w _ i is a string of length at least 1 and at most 100 consisting of lowercase English letters. (1\le i\le Q)
- w _ i is a word in Takahashi-go or Aoki-go. (1\le i\le Q)
- N,M,Q are integers.
Input
The input is given from Standard Input in the following format:
N M S T Q w _ 1 w _ 2 \vdots w _ Q
Output
Print Q lines.
The i-th line should contain Takahashi if it is confirmed that w _ i is a word in Takahashi-go, Aoki if it is confirmed to be a word in Aoki-go, and Unknown if neither can be determined.
Sample Input 1
6 5 ahikst aikot 5 asahi okita kiai hash it
Sample Output 1
Takahashi Aoki Unknown Takahashi Unknown
For example, all of a, s, h, i are used in Takahashi-go, and h is not used in Aoki-go, so it is confirmed that asahi is a word in Takahashi-go.
Thus, print Takahashi on the first line.
Both i and t are used in both Takahashi-go and Aoki-go, so it cannot be determined whether it is a word in Takahashi-go or Aoki-go.
Thus, print Unknown on the fifth line.
Sample Input 2
7 6 ahiknst ahikos 5 kioki ohiki tashi nishi kashi
Sample Output 2
Aoki Aoki Takahashi Takahashi Unknown
o is not used in Takahashi-go, so the first two words are confirmed to be words in Aoki-go.
Thus, print Aoki on the first and second lines.
t and n are not used in Aoki-go, so the following two words are confirmed to be words in Takahashi-go.
Thus, print Takahashi on the third and fourth lines.
For the first four words, there is a rule that words ending in shi are Takahashi-go, and words ending in ki are Aoki-go. However, all of k, a, s, h, i are used in both Takahashi-go and Aoki-go, so it is impossible to determine which language the word kashi belongs to based on the characters used.
Thus, print Unknown on the fifth line.
Sample Input 3
13 11 defghiqsvwxyz acejmoqrtwx 15 qhsqzhd jcareec wwqxqew wxqxwex jxxrtwa trtqjxe sqyggse xxqwxew xewwxxw wwqxwex xqqxqwq qxxexxe teqeroc eeeqqee vxdevyy
Sample Output 3
Takahashi Aoki Unknown Unknown Aoki Aoki Takahashi Unknown Unknown Unknown Unknown Unknown Aoki Unknown Takahashi
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
入学試験の受験者が N 人います。
試験の結果、 i 番の受験生は数学で A_i 点、英語で B_i 点を取りました。
試験の合格者は次のように決められます。
- 数学の点が高い方から X 人を合格とする。
- 次に、この時点でまだ合格となっていない受験者のうち、英語の点が高い方から Y 人を合格とする。
- 次に、この時点でまだ合格となっていない受験者のうち、数学と英語の合計点が高い方から Z 人を合格とする。
- ここまでで合格となっていない受験者は、不合格とする。
ただし、 1. から 3. までのどの段階についても、同点であった場合は受験生の番号の小さい方を優先します。入出力例も参照してください。
以上の手順で合格者を決める時、合格となった受験生の番号を小さい方から順に改行区切りで出力してください。
制約
- 入力は全て整数
- 1 \le N \le 1000
- 0 \le X,Y,Z \le N
- 1 \le X+Y+Z \le N
- 0 \le A_i,B_i \le 100
入力
入力は以下の形式で標準入力から与えられる。
N X Y Z A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
合格となった受験生の番号を小さい方から順に改行区切りで出力せよ。
入力例 1
6 1 0 2 80 60 80 60 70 70 40 20 50 90 90 80
出力例 1
1 4 5
- まず、数学の点が高い方から 1 人が合格となります。
- 数学の最高点は 80 点で 1 番の受験生と 3 番の受験生が並んでいますが、受験生の番号が小さい方が優先され 1 番の受験生が合格となります。
- 次に、まだ合格となっていない受験者のうち、英語の点が高い方から 0 人が合格となります。
- 明らかに、ここで合格者が増えることはありません。
- 次に、まだ合格となっていない受験者のうち、数学と英語の合計点が高い方から 2 人が合格となります。
- まず、まだ合格となっていない受験者の中で、合計点が 160 点と最も高い 5 番の受験生が合格となります。
- 次に、まだ合格となっていない受験者の中で、合計点が 150 点の 4 番の受験生と 6 番の受験生が並んでいます。受験生の番号の小さい方が優先され、 4 番の受験生が合格となります。
以上より、合格となる受験生の番号は 1,4,5 なので、小さい方から出力してください。
入力例 2
5 2 1 2 0 100 0 100 0 0 0 100 100 0
出力例 2
1 2 3 4 5
全員が合格となることもあります。
入力例 3
15 4 3 2 30 65 20 95 100 45 70 85 20 35 95 50 40 15 85 0 25 45 35 65 70 80 90 40 55 20 20 45 75 100
出力例 3
2 4 5 6 7 8 11 14 15
Score : 200 points
Problem Statement
N examinees took an entrance exam.
The examinee numbered i scored A_i points in math and B_i points in English.
The admissions are determined as follows.
- X examinees with the highest math scores are admitted.
- Then, among the examinees who are not admitted yet, Y examinees with the highest English scores are admitted.
- Then, among the examinees who are not admitted yet, Z examinees with the highest total scores in math and English are admitted.
- Those examinees who are not admitted yet are rejected.
Here, in each of the steps 1. to 3., ties are broken by examinees' numbers: an examinee with the smaller examinee's number is prioritized. See also Sample Input and Output.
Print the examinees' numbers of the admitted examinees determined by the steps above in ascending order, separated by newlines.
Constraints
- All values in input are integers.
- 1 \le N \le 1000
- 0 \le X,Y,Z \le N
- 1 \le X+Y+Z \le N
- 0 \le A_i,B_i \le 100
Input
Input is given from Standard Input in the following format:
N X Y Z A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Print the examinees' number of the admitted examinees in ascending order, separated by newlines.
Sample Input 1
6 1 0 2 80 60 80 60 70 70 40 20 50 90 90 80
Sample Output 1
1 4 5
- First, 1 examinee with the highest math score is admitted.
- Examinee 1 is tied with Examinee 3, scoring the highest 80 points in math, and the tie is broken by the examinees' numbers, so Examinee 1 is admitted.
- Then, among the examinees who are not admitted yet, 0 examinees with the highest English scores are admitted.
- Obviously, it does not affect the admissions.
- Then, among the examinees who are not admitted yet, 2 examinees with the highest total scores in math and English are admitted.
- First, among the examinees who are not admitted yet, Examinee 5 is admitted, scoring the highest total score of 160 points.
- Next, among the examinees who are not admitted yet, Examinee 4 is tied with Examinee 6, scoring a total score of 150 points. The tie is broken by the examinees' numbers, and Examinee 4 is admitted.
Therefore, the examinees' numbers of the admitted examinees are 1, 4, and 5. Print them in ascending order.
Sample Input 2
5 2 1 2 0 100 0 100 0 0 0 100 100 0
Sample Output 2
1 2 3 4 5
All examinees may be admitted.
Sample Input 3
15 4 3 2 30 65 20 95 100 45 70 85 20 35 95 50 40 15 85 0 25 45 35 65 70 80 90 40 55 20 20 45 75 100
Sample Output 3
2 4 5 6 7 8 11 14 15
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
N 頂点 N 辺の有向グラフがあります。
i 番目の辺は頂点 i から 頂点 A_i に伸びます。 ( i \neq A_i であることは制約より保証されます )
同一頂点を複数回含まない有向閉路をひとつ求めてください。
なお、この問題の制約下で答えが存在することが示せます。
注釈
この問題では、有向閉路とは以下の条件を全て満たす頂点の列 B=(B_1,B_2,\dots,B_M) であるとします。
- M \ge 2
- B_i から B_{i+1} に辺が伸びている。 ( 1 \le i \le M-1 )
- B_M から B_1 に辺が伸びている。
- i \neq j ならば B_i \neq B_j
制約
- 入力は全て整数
- 2 \le N \le 2 \times 10^5
- 1 \le A_i \le N
- A_i \neq i
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
以下の形式で出力せよ。
M B_1 B_2 \dots B_M
M は出力する有向閉路の頂点数であり、 B_i は有向閉路の i 番目の頂点である。
出力は以下の条件を満たす必要がある。
- 2 \le M
- B_{i+1} = A_{B_i} ( 1 \le i \le M-1 )
- B_{1} = A_{B_M}
- B_i \neq B_j ( i \neq j )
答えとして考えられるものが複数ある場合、どれを出力しても正解となる。
入力例 1
7 6 7 2 1 3 4 5
出力例 1
4 7 5 3 2
7 \rightarrow 5 \rightarrow 3 \rightarrow 2 \rightarrow 7 は確かに有向閉路になっています。
この入力に対応するグラフは以下の通りです。

他の正解となる出力の例は以下の通りです。
4 2 7 5 3
3 4 1 6
グラフが連結であるとは限らないことに注意してください。
入力例 2
2 2 1
出力例 2
2 1 2
1 \rightarrow 2 と 2 \rightarrow 1 の辺が双方存在するケースです。
この場合、 1 \rightarrow 2 \rightarrow 1 は確かに有向閉路になっています。
この入力に対応するグラフは以下の通りです。
図中 1 \leftrightarrow 2 で 1 \rightarrow 2 と 2 \rightarrow 1 の辺が双方あることを表現しています。

入力例 3
8 3 7 4 7 3 3 8 2
出力例 3
3 2 7 8
この入力に対応するグラフは以下の通りです。

Score : 350 points
Problem Statement
There is a directed graph with N vertices and N edges.
The i-th edge goes from vertex i to vertex A_i. (The constraints guarantee that i \neq A_i.)
Find a directed cycle without the same vertex appearing multiple times.
It can be shown that a solution exists under the constraints of this problem.
Notes
The sequence of vertices B = (B_1, B_2, \dots, B_M) is called a directed cycle when all of the following conditions are satisfied:
- M \geq 2
- The edge from vertex B_i to vertex B_{i+1} exists. (1 \leq i \leq M-1)
- The edge from vertex B_M to vertex B_1 exists.
- If i \neq j, then B_i \neq B_j.
Constraints
- All input values are integers.
- 2 \le N \le 2 \times 10^5
- 1 \le A_i \le N
- A_i \neq i
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N
Output
Print a solution in the following format:
M B_1 B_2 \dots B_M
M is the number of vertices, and B_i is the i-th vertex in the directed cycle.
The following conditions must be satisfied:
- 2 \le M
- B_{i+1} = A_{B_i} ( 1 \le i \le M-1 )
- B_{1} = A_{B_M}
- B_i \neq B_j ( i \neq j )
If multiple solutions exist, any of them will be accepted.
Sample Input 1
7 6 7 2 1 3 4 5
Sample Output 1
4 7 5 3 2
7 \rightarrow 5 \rightarrow 3 \rightarrow 2 \rightarrow 7 is indeed a directed cycle.
Here is the graph corresponding to this input:

Here are other acceptable outputs:
4 2 7 5 3
3 4 1 6
Note that the graph may not be connected.
Sample Input 2
2 2 1
Sample Output 2
2 1 2
This case contains both of the edges 1 \rightarrow 2 and 2 \rightarrow 1.
In this case, 1 \rightarrow 2 \rightarrow 1 is indeed a directed cycle.
Here is the graph corresponding to this input, where 1 \leftrightarrow 2 represents the existence of both 1 \rightarrow 2 and 2 \rightarrow 1:

Sample Input 3
8 3 7 4 7 3 3 8 2
Sample Output 3
3 2 7 8
Here is the graph corresponding to this input:
