Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英大文字からなる長さ 3 の文字列 S が与えられます。S が ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれかと等しいとき Yes を、そうでないとき No を出力してください。
制約
- S は英大文字からなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれかと等しいとき Yes を、そうでないとき No を出力せよ。
入力例 1
ABC
出力例 1
No
S = ABC のとき、S は ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれとも等しくないので No を出力します。
入力例 2
FAC
出力例 2
Yes
入力例 3
XYX
出力例 3
No
Score : 100 points
Problem Statement
Given a length-3 string S consisting of uppercase English letters, print Yes if S equals one of ACE, BDF, CEG, DFA, EGB, FAC, and GBD; print No otherwise.
Constraints
- S is a length-3 string consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if S equals one of ACE, BDF, CEG, DFA, EGB, FAC, and GBD; print No otherwise.
Sample Input 1
ABC
Sample Output 1
No
When S = ABC, S does not equal any of ACE, BDF, CEG, DFA, EGB, FAC, and GBD, so No should be printed.
Sample Input 2
FAC
Sample Output 2
Yes
Sample Input 3
XYX
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋くんと青木くんが N 回の試合を行いました。
これらの試合の結果を表す長さ N の文字列 S が与えられます。
i 回目の試合の勝者は、S の i 文字目が T ならば高橋くん、A ならば青木くんです。
高橋くんと青木くんのうち、勝った試合の数が多い方を総合勝者とします。 ただし、勝った試合の数が同じである場合は、先にその勝ち数に達した者を総合勝者とします。 高橋くんと青木くんのどちらが総合勝者であるか求めてください。
制約
- 1\leq N \leq 100
- N は整数
- S は
TおよびAからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
総合勝者が高橋くんならば T を、青木くんならば A を出力せよ。
入力例 1
5 TTAAT
出力例 1
T
高橋くんは 3 回の試合に勝ち、青木くんは 2 回の試合に勝ちました。 よって、勝った試合の数が多い高橋くんが総合勝者です。
入力例 2
6 ATTATA
出力例 2
T
高橋くんと青木くんのどちらも 3 回の試合に勝ちました。 また、高橋くんは 5 回目の試合で 3 勝目に達し、青木くんは 6 回目の試合で 3 勝目に達しました。 よって、先に 3 勝目に達した高橋くんが総合勝者です。
入力例 3
1 A
出力例 3
A
Score : 100 points
Problem Statement
Takahashi and Aoki played N games.
You are given a string S of length N, representing the results of these games.
Takahashi won the i-th game if the i-th character of S is T, and Aoki won that game if it is A.
The overall winner between Takahashi and Aoki is the one who won more games than the other. If they had the same number of wins, the overall winner is the one who reached that number of wins first. Find the overall winner: Takahashi or Aoki.
Constraints
- 1\leq N \leq 100
- N is an integer.
- S is a string of length N consisting of
TandA.
Input
The input is given from Standard Input in the following format:
N S
Output
If the overall winner is Takahashi, print T; if it is Aoki, print A.
Sample Input 1
5 TTAAT
Sample Output 1
T
Takahashi won three games, and Aoki won two. Thus, the overall winner is Takahashi, who won more games.
Sample Input 2
6 ATTATA
Sample Output 2
T
Both Takahashi and Aoki won three games. Takahashi reached three wins in the fifth game, and Aoki in the sixth game. Thus, the overall winner is Takahashi, who reached three wins first.
Sample Input 3
1 A
Sample Output 3
A
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
人 1, 人 2, \dots 人 N の N 人の人がいます。人 i の姓は s_i、名は t_i です。
N 人の人すべてにあだ名をつけることを考えます。人 i のあだ名 a_i は以下の条件を満たす必要があります。
- a_i は人 i の姓あるいは名と一致する。言い換えると、a_i = s_i または a_i = t_i の少なくとも一方が成り立つ。
- a_i は自分以外の人の姓および名のどちらとも一致しない。言い換えると、1 \leq j \leq N, i \neq j を満たすすべての整数 j について a_i \neq s_j かつ a_i \neq t_j が成り立つ。
N 人全員に条件を満たすあだ名をつけることは可能でしょうか。可能ならば Yes を、そうでないならば No を出力してください。
制約
- 2 \leq N \leq 100
- N は整数である。
- s_i,t_i は英小文字からなる 1 文字以上 10 文字以下の文字列である。
入力
入力は以下の形式で標準入力から与えられる。
N s_1 t_1 s_2 t_2 \vdots s_N t_N
出力
N 人すべてにあだ名をつけることが可能ならば Yes を、そうでないならば No を出力せよ。
入力例 1
3 tanaka taro tanaka jiro suzuki hanako
出力例 1
Yes
a_1 = taro, a_2 = jiro, a_3 = hanako とすれば、これは問題文にあるあだ名の条件を満たしています。(a_3 は suzuki でもよいです。)
ここで、a_1 = tanaka とはできないことに注意してください。なぜならば 人 2 の姓 s_2 もまた tanaka であるため、あだ名の条件の 2 つ目を満たさなくなるからです。
入力例 2
3 aaa bbb xxx aaa bbb yyy
出力例 2
No
問題文の条件を満たすあだ名のつけ方は存在しません。
入力例 3
2 tanaka taro tanaka taro
出力例 3
No
同姓同名である人の組が存在する場合もあります。
入力例 4
3 takahashi chokudai aoki kensho snu ke
出力例 4
Yes
a_1 = chokudai, a_2 = kensho, a_3 = ke とすればよいです。
Score : 200 points
Problem Statement
There are N people numbered Person 1, Person 2, \dots, and Person N. Person i has a family name s_i and a given name t_i.
Consider giving a nickname to each of the N people. Person i's nickname a_i should satisfy all the conditions below.
- a_i coincides with Person i's family name or given name. In other words, a_i = s_i and/or a_i = t_i holds.
- a_i does not coincide with the family name and the given name of any other person. In other words, for all integer j such that 1 \leq j \leq N and i \neq j, it holds that a_i \neq s_j and a_i \neq t_j.
Is it possible to give nicknames to all the N people? If it is possible, print Yes; otherwise, print No.
Constraints
- 2 \leq N \leq 100
- N is an integer.
- s_i and t_i are strings of lengths between 1 and 10 (inclusive) consisting of lowercase English alphabets.
Input
Input is given from Standard Input in the following format:
N s_1 t_1 s_2 t_2 \vdots s_N t_N
Output
If it is possible to give nicknames to all the N people, print Yes; otherwise, print No.
Sample Input 1
3 tanaka taro tanaka jiro suzuki hanako
Sample Output 1
Yes
The following assignment satisfies the conditions of nicknames described in the Problem Statement: a_1 = taro, a_2 = jiro, a_3 = hanako. (a_3 may be suzuki, too.)
However, note that we cannot let a_1 = tanaka, which violates the second condition of nicknames, since Person 2's family name s_2 is tanaka too.
Sample Input 2
3 aaa bbb xxx aaa bbb yyy
Sample Output 2
No
There is no way to give nicknames satisfying the conditions in the Problem Statement.
Sample Input 3
2 tanaka taro tanaka taro
Sample Output 3
No
There may be a pair of people with the same family name and the same given name.
Sample Input 4
3 takahashi chokudai aoki kensho snu ke
Sample Output 4
Yes
We can let a_1 = chokudai, a_2 = kensho, and a_3 = ke.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
xy 平面上に 1 から N までの番号が付いた N 個の点があります。点 i は座標 (X_i, Y_i) にあり、相異なる 2 点の座標は異なります。
各点について、その点からの距離が最大である点を求めてその点の番号を出力してください。 ただし、距離が最大である点が複数ある場合はその中で最も番号が小さい点の番号を出力してください。
ここで、距離はユークリッド距離、すなわち 2 点 (x_1,y_1) と (x_2,y_2) に対し、この 2 点間の距離が \sqrt{(x_1-x_2)^{2}+(y_1-y_2)^{2}} であるものとして定められています。
制約
- 2 \leq N \leq 100
- -1000 \leq X_i, Y_i \leq 1000
- i \neq j ならば (X_i, Y_i) \neq (X_j, Y_j)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
出力
N 行出力せよ。i 行目には点 i からの距離が最大である点の番号を出力せよ。
入力例 1
4 0 0 2 4 5 0 3 4
出力例 1
3 3 1 1
以下の図のように点が並んでいます。ここで P_i は点 i を表します。
点 1 からの距離が最大である点は点 3,4 で、その中で番号が小さいのは点 3 です。
点 2 からの距離が最大である点は点 3 です。
点 3 からの距離が最大である点は点 1,2 で、その中で番号が小さいのは点 1 です。
点 4 からの距離が最大である点は点 1 です。
入力例 2
6 3 2 1 6 4 5 1 3 5 5 9 8
出力例 2
6 6 6 6 6 4
Score: 200 points
Problem Statement
On the xy-plane, there are N points with ID numbers from 1 to N. Point i is located at coordinates (X_i, Y_i), and no two points have the same coordinates.
From each point, find the farthest point and print its ID number. If multiple points are the farthest, print the smallest of the ID numbers of those points.
Here, we use the Euclidean distance: for two points (x_1,y_1) and (x_2,y_2), the distance between them is \sqrt{(x_1-x_2)^{2}+(y_1-y_2)^{2}}.
Constraints
- 2 \leq N \leq 100
- -1000 \leq X_i, Y_i \leq 1000
- (X_i, Y_i) \neq (X_j, Y_j) if i \neq j.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
Output
Print N lines. The i-th line should contain the ID number of the farthest point from point i.
Sample Input 1
4 0 0 2 4 5 0 3 4
Sample Output 1
3 3 1 1
The following figure shows the arrangement of the points. Here, P_i represents point i.
The farthest point from point 1 are points 3 and 4, and point 3 has the smaller ID number.
The farthest point from point 2 is point 3.
The farthest point from point 3 are points 1 and 2, and point 1 has the smaller ID number.
The farthest point from point 4 is point 1.
Sample Input 2
6 3 2 1 6 4 5 1 3 5 5 9 8
Sample Output 2
6 6 6 6 6 4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
文字列 S の各文字を並べ替えて作ることが可能な文字列を辞書順にすべて列挙したとき、前から K 番目にくる文字列を求めてください。
「各文字を並べ替えて作ることが可能な文字列」とは?
「文字列 A が文字列 B の各文字を並べ替えて作ることが可能な文字列である」とは、任意の文字が文字列 A と文字列 B に同数含まれるということを指します。制約
- 1 \le |S| \le 8
- S は英小文字のみからなる
- S の各文字を並べ替えてできる文字列は K 種類以上存在する
入力
入力は以下の形式で標準入力から与えられる。
S K
出力
答えを出力せよ。
入力例 1
aab 2
出力例 1
aba
文字列 aab の各文字を並べ替えて作ることが可能な文字列は \{ aab, aba, baa \} の 3 つですが、このうち辞書順で前から 2 番目にくるものは aba です。
入力例 2
baba 4
出力例 2
baab
入力例 3
ydxwacbz 40320
出力例 3
zyxwdcba
Score : 300 points
Problem Statement
Find the K-th lexicographically smallest string among the strings that are permutations of a string S.
What is a permutation of a string?
A string A is said to be a permutation of a string B when any character occurs the same number of times in A and B.Constraints
- 1 \le |S| \le 8
- S consists of lowercase English letters.
- There are at least K distinct strings that are permutations of S.
Input
Input is given from Standard Input in the following format:
S K
Output
Print the answer.
Sample Input 1
aab 2
Sample Output 1
aba
There are three permutations of a string aab: \{ aab, aba, baa \}. The 2-nd lexicographically smallest of them is aba.
Sample Input 2
baba 4
Sample Output 2
baab
Sample Input 3
ydxwacbz 40320
Sample Output 3
zyxwdcba