実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
x 軸の正の向きが右、y 軸の正の向きが上であるような xy 座標平面において、点 (a,b) を原点を中心として反時計回りに d 度回転させた点を求めてください。
制約
- -1000 \leq a,b \leq 1000
- 1 \leq d \leq 360
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
a b d
出力
求めるべき点を (a',b') とするとき、 a' と b' をこの順に空白区切りで出力せよ。
なお、各出力について、解との絶対誤差または相対誤差が 10^{−6} 以下であれば正解として扱われる。
入力例 1
2 2 180
出力例 1
-2 -2
(2,2) を原点を中心として反時計回りに 180 度回転させた点は、(2,2) を原点について対称な位置に移動させた点であり、(-2,-2) となります。
入力例 2
5 0 120
出力例 2
-2.49999999999999911182 4.33012701892219364908
(5,0) を原点を中心として反時計回りに 120 度回転させた点は (-\frac {5}{2} , \frac {5\sqrt{3}}{2}) です。
この例での出力はこれらの値と厳密には一致しませんが、誤差が十分に小さいため正解として扱われます。
入力例 3
0 0 11
出力例 3
0.00000000000000000000 0.00000000000000000000
(a,b) が原点(回転の中心)なので回転させても座標が変わりません。
入力例 4
15 5 360
出力例 4
15.00000000000000177636 4.99999999999999555911
360 度回転させたので座標が変わりません。
入力例 5
-505 191 278
出力例 5
118.85878514480690171240 526.66743699786547949770
Score : 200 points
Problem Statement
In an xy-coordinate plane whose x-axis is oriented to the right and whose y-axis is oriented upwards, rotate a point (a, b) around the origin d degrees counterclockwise and find the new coordinates of the point.
Constraints
- -1000 \leq a,b \leq 1000
- 1 \leq d \leq 360
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
a b d
Output
Let the new coordinates of the point be (a', b'). Print a' and b' in this order, with a space in between.
Your output will be considered correct when, for each value printed, the absolute or relative error from the answer is at most 10^{-6}.
Sample Input 1
2 2 180
Sample Output 1
-2 -2
When (2, 2) is rotated around the origin 180 degrees counterclockwise, it becomes the symmetric point of (2, 2) with respect to the origin, which is (-2, -2).
Sample Input 2
5 0 120
Sample Output 2
-2.49999999999999911182 4.33012701892219364908
When (5, 0) is rotated around the origin 120 degrees counterclockwise, it becomes (-\frac {5}{2} , \frac {5\sqrt{3}}{2}).
This sample output does not precisely match these values, but the errors are small enough to be considered correct.
Sample Input 3
0 0 11
Sample Output 3
0.00000000000000000000 0.00000000000000000000
Since (a, b) is the origin (the center of rotation), a rotation does not change its coordinates.
Sample Input 4
15 5 360
Sample Output 4
15.00000000000000177636 4.99999999999999555911
A 360-degree rotation does not change the coordinates of a point.
Sample Input 5
-505 191 278
Sample Output 5
118.85878514480690171240 526.66743699786547949770
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君の家には N 個の食品があり、i 番目の食品のおいしさは A_i です。
また、高橋君には嫌いな食品が K 個あり、具体的には i=1,2,\ldots,K について、B_i 番目の食品が嫌いです。
高橋君は N 個の食品のうち、おいしさが最大の食品から 1 つを選んで食べようと考えています。
高橋君が嫌いな食品を食べる可能性があるならば Yes
を、食べる可能性が無いならば No
を出力してください。
制約
- 1\leq K\leq N\leq 100
- 1\leq A_i\leq 100
- 1\leq B_i\leq N
- B_i はすべて相異なる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_K
出力
高橋君が嫌いな食品を食べる可能性があるならば Yes
を、無いならば No
を出力せよ。
入力例 1
5 3 6 8 10 7 10 2 3 4
出力例 1
Yes
5 個の食品の中でおいしさが最大の食品は食品 3 と 5 の 2 つであり、この 2 つのいずれかを食べます。
高橋君が嫌いな食品は 2,3,4 の 3 つであり、そのうち食品 3 を食べる可能性があります。
よって、Yes
を出力します。
入力例 2
5 2 100 100 100 1 1 5 4
出力例 2
No
おいしさが最大の食品は食品 1,2,3 の 3 つであり、高橋君は嫌いな食品を食べる可能性はありません。
入力例 3
2 1 100 1 2
出力例 3
No
おいしさが最大の食品は食品 1 であり、高橋君は嫌いな食品を食べる可能性はありません。
Score : 200 points
Problem Statement
Takahashi has N foods in his house. The i-th food has the tastiness of A_i.
He dislikes K of these foods: for each i=1,2,\ldots,K, he dislikes the B_i-th food.
Out of the foods with the greatest tastiness among the N foods, Takahashi will randomly choose one and eat it.
If he has a chance to eat something he dislikes, print Yes
; otherwise, print No
.
Constraints
- 1\leq K\leq N\leq 100
- 1\leq A_i\leq 100
- 1\leq B_i\leq N
- All B_i are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_K
Output
If Takahashi has a chance to eat a food he dislikes, print Yes
; otherwise, print No
.
Sample Input 1
5 3 6 8 10 7 10 2 3 4
Sample Output 1
Yes
Among the five foods, the ones with the greatest tastiness are Food 3 and 5, of which he eats one.
He dislikes Food 2, 3, and 4, one of which he has a chance to eat: Food 3.
Therefore, the answer is Yes
.
Sample Input 2
5 2 100 100 100 1 1 5 4
Sample Output 2
No
The foods with the greatest tastiness are Food 1, 2, and 3, none of which he has a chance to eat.
Sample Input 3
2 1 100 1 2
Sample Output 3
No
The food with the greatest tastiness is Food 1, which he has no chance to eat.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
この問題は F 問題 (Operate K) の部分問題であり、 K=1 です。
F 問題に正解するコードをこの問題に提出することで、この問題に正解できます。
文字列 S に対して以下の操作を 0 回以上 K 回以下行って、文字列 T と一致させられるか判定してください。
- 次の 3 種類の操作のうちひとつを選択し、実行する。
- S 中の (先頭や末尾を含む) 任意の位置に、任意の文字を 1 つ挿入する。
- S 中の文字を 1 つ選び、削除する。
- S 中の文字を 1 つ選び、別の 1 つの文字に変更する。
制約
- S,T は英小文字からなる長さ 1 以上 500000 以下の文字列
- \color{red}{K=1}
入力
入力は以下の形式で標準入力から与えられる。
K S T
出力
K 回以下の操作で S を T に一致させられる時 Yes
、そうでない時 No
と出力せよ。
入力例 1
1 abc agc
出力例 1
Yes
abc
の 2 文字目の b
を g
に置き換えることで、 abc
を 1 回の操作で agc
に変換できます。
入力例 2
1 abc awtf
出力例 2
No
1 回の操作では abc
を awtf
に変換できません。
入力例 3
1 abc ac
出力例 3
Yes
abc
の 2 文字目の b
を削除することで、 abc
を 1 回の操作で ac
に変換できます。
入力例 4
1 back black
出力例 4
Yes
back
の 1 文字目と 2 文字目の間に l
を挿入することで、 back
を 1 回の操作で black
に変換できます。
入力例 5
1 same same
出力例 5
Yes
初めから S=T である場合もあります。
入力例 6
1 leap read
出力例 6
No
Score : 350 points
Problem Statement
This problem is a sub-problem of Problem F (Operate K), with K=1.
You can solve this problem by submitting a correct solution for Problem F to this problem.
Determine whether it is possible to perform the following operation on string S between 0 and K times, inclusive, to make it identical to string T.
- Choose one of the following three operations and execute it.
- Insert any one character at any position in S (possibly the beginning or end).
- Delete one character from S.
- Choose one character in S and replace it with another character.
Constraints
- Each of S and T is a string of length between 1 and 500000, inclusive, consisting of lowercase English letters.
- \color{red}{K=1}
Input
The input is given from Standard Input in the following format:
K S T
Output
If S can be made identical to T with at most K operations, print Yes
; otherwise, print No
.
Sample Input 1
1 abc agc
Sample Output 1
Yes
Replacing the second character b
of abc
with g
converts abc
to agc
in one operation.
Sample Input 2
1 abc awtf
Sample Output 2
No
abc
cannot be converted to awtf
in one operation.
Sample Input 3
1 abc ac
Sample Output 3
Yes
Deleting the second character b
of abc
converts abc
to ac
in one operation.
Sample Input 4
1 back black
Sample Output 4
Yes
Inserting l
between the first and second characters of back
converts back
to black
in one operation.
Sample Input 5
1 same same
Sample Output 5
Yes
It is also possible that S = T from the beginning.
Sample Input 6
1 leap read
Sample Output 6
No
実行時間制限: 2 sec / メモリ制限: 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
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N 人のスポーツ選手がいます。
N 人の選手たちには互いに相性の悪い選手のペアが M 組あり、相性の悪い組のうち i\ (1\leq i\leq M) 組目は A _ i 番目の選手と B _ i 番目の選手です。
あなたは、選手を T チームに分けます。 どの選手もちょうど一つのチームに属さなければならず、どのチームにも少なくとも一人の選手が属さなければなりません。 さらに、どの i=1,2,\ldots,M についても、 A _ i 番目の選手と B _ i 番目の選手が同じチームに属していてはいけません。
この条件を満たすチーム分けの方法は何通りあるか求めてください。 ただし、チーム分けの方法が異なるとは、ある二人が存在して、彼らが一方のチーム分けでは同じチームに所属し、もう一方では異なるチームに所属することをいいます。
制約
- 1\leq T\leq N\leq10
- 0\leq M\leq\dfrac{N(N-1)}2
- 1\leq A _ i\lt B _ i\leq N\ (1\leq i\leq M)
- (A _ i,B _ i)\neq (A _ j,B _ j)\ (1\leq i\lt j\leq M)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N T M A _ 1 B _ 1 A _ 2 B _ 2 \vdots A _ M B _ M
出力
答えを 1 行で出力せよ。
入力例 1
5 2 2 1 3 3 4
出力例 1
4
次の 4 通りのチーム分けが条件を満たします。
他に条件を満たすチーム分けは存在しないので、4 を出力してください。
入力例 2
5 1 2 1 3 3 4
出力例 2
0
条件を満たすチーム分けがひとつも存在しないこともあります。
入力例 3
6 4 0
出力例 3
65
相性の悪いペアがひとつも存在しないこともあります。
入力例 4
10 6 8 5 9 1 4 3 8 1 6 4 10 5 7 5 6 3 7
出力例 4
8001
Score : 400 points
Problem Statement
There are N sports players.
Among them, there are M incompatible pairs. The i-th incompatible pair (1\leq i\leq M) is the A_i-th and B_i-th players.
You will divide the players into T teams. Every player must belong to exactly one team, and every team must have one or more players. Additionally, for each i=1,2,\ldots,M, the A_i-th and B_i-th players must not belong to the same team.
Find the number of ways to satisfy these conditions. Here, two divisions are considered different when there are two players who belong to the same team in one division and different teams in the other.
Constraints
- 1\leq T\leq N\leq10
- 0\leq M\leq\dfrac{N(N-1)}2
- 1\leq A _ i\lt B _ i\leq N\ (1\leq i\leq M)
- (A _ i,B _ i)\neq (A _ j,B _ j)\ (1\leq i\lt j\leq M)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T M A _ 1 B _ 1 A _ 2 B _ 2 \vdots A _ M B _ M
Output
Print the answer in a single line.
Sample Input 1
5 2 2 1 3 3 4
Sample Output 1
4
The following four divisions satisfy the conditions.
No other division satisfies them, so print 4.
Sample Input 2
5 1 2 1 3 3 4
Sample Output 2
0
There may be no division that satisfies the conditions.
Sample Input 3
6 4 0
Sample Output 3
65
There may be no incompatible pair.
Sample Input 4
10 6 8 5 9 1 4 3 8 1 6 4 10 5 7 5 6 3 7
Sample Output 4
8001