Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
果物屋さんでりんごが売られています。
あなたは次の操作を好きな順で好きなだけ繰り返すことができます。
- X 円を払ってりんごを 1 個手に入れる。
- Y 円を払ってりんごを 3 個手に入れる。
りんごをちょうど N 個手に入れるには最低何円必要ですか?
制約
- 1 \leq X \leq Y \leq 100
- 1 \leq N \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
X Y N
出力
答えを整数として出力せよ。
入力例 1
10 25 10
出力例 1
85
25 円払って 3 個のりんごを手に入れる操作を 3 回繰り返した後、10 円払って 1 個のりんごを手に入れると丁度 10 個のりんごを手に入れられます。このときあなたは 85 円を消費します。
これより少ない金額でちょうど 10 個のりんごを手に入れることはできないので、答えは 85 円になります。
入力例 2
10 40 10
出力例 2
100
10 円払って 1 個のりんごを手に入れる操作を 10 回繰り返すのが最適です。
入力例 3
100 100 2
出力例 3
200
100 円を払って 1 個のりんごを手に入れる操作を 2 回繰り返す以外に ちょうど 2 個のりんごを手に入れる方法はありません。
入力例 4
100 100 100
出力例 4
3400
Score : 100 points
Problem Statement
A fruit store sells apples.
You may perform the following operations as many times as you want in any order:
- Buy one apple for X yen (the currency in Japan).
- Buy three apples for Y yen.
How much yen do you need to pay to obtain exactly N apples?
Constraints
- 1 \leq X \leq Y \leq 100
- 1 \leq N \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y N
Output
Print the answer as an integer.
Sample Input 1
10 25 10
Sample Output 1
85
Buy three apples for 25 yen three times and one apple for 10 yen, and you will obtain exactly 10 apples for a total of 85 yen.
You cannot obtain exactly 10 apples for a lower cost, so the answer is 85 yen.
Sample Input 2
10 40 10
Sample Output 2
100
It is optimal to buy an apple for 10 yen 10 times.
Sample Input 3
100 100 2
Sample Output 3
200
The only way to obtain exactly 2 apples is to buy an apple for 100 yen twice.
Sample Input 4
100 100 100
Sample Output 4
3400
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
二つの文字 x と y は以下の 3 つの条件のうちどれか 1 つを満たすとき、似た文字と呼ばれます。
- x と y は同じ文字
- x と y の片方が
1で、もう片方がl - x と y の片方が
0で、もう片方がo
また、長さ N の文字列 S と T は以下の条件を満たすとき、似た文字列と呼ばれます。
- 任意の i\ (1\leq i\leq N) について、 S の i 番目の文字と T の i 番目の文字は似た文字
英小文字及び数字からなる長さ N の文字列 S,T が与えられます。 S と T が似た文字列か判定してください。
制約
- N は 1 以上 100 以下の整数
- S,T は英小文字及び数字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S T
出力
S と T が似た文字列の場合 Yes を、そうでない場合 No を出力せよ。
入力例 1
3 l0w 1ow
出力例 1
Yes
S の 1 文字目は lで、T の 1 文字目は 1です。これらは似た文字です。
S の 2 文字目は 0で、T の 2 文字目は oです。これらは似た文字です。
S の 3 文字目は wで、T の 3 文字目は wです。これらは似た文字です。
よって S と T は似た文字列です。
入力例 2
3 abc arc
出力例 2
No
S の 2 文字目は bで、T の 2 文字目は rです。これらは似た文字ではありません。
よって S と T は似た文字列ではありません。
入力例 3
4 nok0 n0ko
出力例 3
Yes
Score : 100 points
Problem Statement
Two characters x and y are called similar characters if and only if one of the following conditions is satisfied:
- x and y are the same character.
- One of x and y is
1and the other isl. - One of x and y is
0and the other iso.
Two strings S and T, each of length N, are called similar strings if and only if:
- for all i\ (1\leq i\leq N), the i-th character of S and the i-th character of T are similar characters.
Given two length-N strings S and T consisting of lowercase English letters and digits, determine if S and T are similar strings.
Constraints
- N is an integer between 1 and 100.
- Each of S and T is a string of length N consisting of lowercase English letters and digits.
Input
The input is given from Standard Input in the following format:
N S T
Output
Print Yes if S and T are similar strings, and No otherwise.
Sample Input 1
3 l0w 1ow
Sample Output 1
Yes
The 1-st character of S is l, and the 1-st character of T is 1. These are similar characters.
The 2-nd character of S is 0, and the 2-nd character of T is o. These are similar characters.
The 3-rd character of S is w, and the 3-rd character of T is w. These are similar characters.
Thus, S and T are similar strings.
Sample Input 2
3 abc arc
Sample Output 2
No
The 2-nd character of S is b, and the 2-nd character of T is r. These are not similar characters.
Thus, S and T are not similar strings.
Sample Input 3
4 nok0 n0ko
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
縦 H 行、横 W 列のマス目があり、各マスには 1 つの整数が書かれています。 上から i 行目、左から j 列目のマスに書かれている整数は A_{i, j} です。
マス目が下記の条件を満たすかどうかを判定してください。
1 \leq i_1 < i_2 \leq H および 1 \leq j_1 < j_2 \leq W を満たすすべての整数の組 (i_1, i_2, j_1, j_2) について、A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2} が成り立つ。
制約
- 2 \leq H, W \leq 50
- 1 \leq A_{i, j} \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W
A_{1, 1} A_{1, 2} \cdots A_{1, W}
A_{2, 1} A_{2, 2} \cdots A_{2, W}
\vdots
A_{H, 1} A_{H, 2} \cdots A_{H, W}
出力
マス目が問題文中の条件を満たす場合は Yes と出力し、条件を満たさない場合は No と出力せよ。
入力例 1
3 3 2 1 4 3 1 3 6 4 1
出力例 1
Yes
1 \leq i_1 < i_2 \leq H および 1 \leq j_1 < j_2 \leq W を満たす整数の組 (i_1, i_2, j_1, j_2) は 9 個存在し、それらすべてについて A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2} が成り立ちます。例えば、
- (i_1, i_2, j_1, j_2) = (1, 2, 1, 2) について、A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 3 + 1 = A_{i_2, j_1} + A_{i_1, j_2}
- (i_1, i_2, j_1, j_2) = (1, 2, 1, 3) について、A_{i_1, j_1} + A_{i_2, j_2} = 2 + 3 \leq 3 + 4 = A_{i_2, j_1} + A_{i_1, j_2}
- (i_1, i_2, j_1, j_2) = (1, 2, 2, 3) について、A_{i_1, j_1} + A_{i_2, j_2} = 1 + 3 \leq 1 + 4 = A_{i_2, j_1} + A_{i_1, j_2}
- (i_1, i_2, j_1, j_2) = (1, 3, 1, 2) について、A_{i_1, j_1} + A_{i_2, j_2} = 2 + 4 \leq 6 + 1 = A_{i_2, j_1} + A_{i_1, j_2}
- (i_1, i_2, j_1, j_2) = (1, 3, 1, 3) について、A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 6 + 4 = A_{i_2, j_1} + A_{i_1, j_2}
が成り立ちます。残りの (i_1, i_2, j_1, j_2) = (1, 3, 2, 3), (2, 3, 1, 2), (2, 3, 1, 3), (2, 3, 2, 3) についても同様に確認できます。
よって、Yes を出力します。
入力例 2
2 4 4 3 2 1 5 6 7 8
出力例 2
No
問題文中の条件を満たさないので、No を出力します。
例えば、(i_1, i_2, j_1, j_2) = (1, 2, 1, 4) について、A_{i_1, j_1} + A_{i_2, j_2} = 4 + 8 > 5 + 1 = A_{i_2, j_1} + A_{i_1, j_2} です。
Score : 200 points
Problem Statement
We have a grid with H horizontal rows and W vertical columns, where each square contains an integer. The integer written on the square at the i-th row from the top and j-th column from the left is A_{i, j}.
Determine whether the grid satisfies the condition below.
A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2} holds for every quadruple of integers (i_1, i_2, j_1, j_2) such that 1 \leq i_1 < i_2 \leq H and 1 \leq j_1 < j_2 \leq W.
Constraints
- 2 \leq H, W \leq 50
- 1 \leq A_{i, j} \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W
A_{1, 1} A_{1, 2} \cdots A_{1, W}
A_{2, 1} A_{2, 2} \cdots A_{2, W}
\vdots
A_{H, 1} A_{H, 2} \cdots A_{H, W}
Output
If the grid satisfies the condition in the Problem Statement, print Yes; otherwise, print No.
Sample Input 1
3 3 2 1 4 3 1 3 6 4 1
Sample Output 1
Yes
There are nine quadruples of integers (i_1, i_2, j_1, j_2) such that 1 \leq i_1 < i_2 \leq H and 1 \leq j_1 < j_2 \leq W. For all of them, A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2} holds. Some examples follow.
- For (i_1, i_2, j_1, j_2) = (1, 2, 1, 2), we have A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 3 + 1 = A_{i_2, j_1} + A_{i_1, j_2}.
- For (i_1, i_2, j_1, j_2) = (1, 2, 1, 3), we have A_{i_1, j_1} + A_{i_2, j_2} = 2 + 3 \leq 3 + 4 = A_{i_2, j_1} + A_{i_1, j_2}.
- For (i_1, i_2, j_1, j_2) = (1, 2, 2, 3), we have A_{i_1, j_1} + A_{i_2, j_2} = 1 + 3 \leq 1 + 4 = A_{i_2, j_1} + A_{i_1, j_2}.
- For (i_1, i_2, j_1, j_2) = (1, 3, 1, 2), we have A_{i_1, j_1} + A_{i_2, j_2} = 2 + 4 \leq 6 + 1 = A_{i_2, j_1} + A_{i_1, j_2}.
- For (i_1, i_2, j_1, j_2) = (1, 3, 1, 3), we have A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 6 + 4 = A_{i_2, j_1} + A_{i_1, j_2}.
We can also see that the property holds for the other quadruples: (i_1, i_2, j_1, j_2) = (1, 3, 2, 3), (2, 3, 1, 2), (2, 3, 1, 3), (2, 3, 2, 3).
Thus, we should print Yes.
Sample Input 2
2 4 4 3 2 1 5 6 7 8
Sample Output 2
No
We should print No because the condition is not satisfied.
This is because, for example, we have A_{i_1, j_1} + A_{i_2, j_2} = 4 + 8 > 5 + 1 = A_{i_2, j_1} + A_{i_1, j_2} for (i_1, i_2, j_1, j_2) = (1, 2, 1, 4).
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
整数 N が与えられます。
非負整数の組 (x,y,z) であって x+y+z\leq N を満たすものを辞書順で小さい方から順に全て出力してください。
非負整数の組の辞書順とは?
非負整数の組 (x,y,z) が (x',y',z') より辞書順で小さいとは、下記のいずれかが成り立つことを言います。
- x < x' である
- x=x' かつ y< y' である
- x=x' かつ y=y' かつ z< z' である
制約
- 0 \leq N \leq 21
- N は整数である
入力
入力は以下の形式で標準入力から与えられる。
N
出力
非負整数の組 (x,y,z) であって x+y+z\leq N を満たすものを、1 行に 1 組ずつ x,y,z を空白区切りで、辞書順で小さい方から順に全て出力せよ。
入力例 1
3
出力例 1
0 0 0 0 0 1 0 0 2 0 0 3 0 1 0 0 1 1 0 1 2 0 2 0 0 2 1 0 3 0 1 0 0 1 0 1 1 0 2 1 1 0 1 1 1 1 2 0 2 0 0 2 0 1 2 1 0 3 0 0
入力例 2
4
出力例 2
0 0 0 0 0 1 0 0 2 0 0 3 0 0 4 0 1 0 0 1 1 0 1 2 0 1 3 0 2 0 0 2 1 0 2 2 0 3 0 0 3 1 0 4 0 1 0 0 1 0 1 1 0 2 1 0 3 1 1 0 1 1 1 1 1 2 1 2 0 1 2 1 1 3 0 2 0 0 2 0 1 2 0 2 2 1 0 2 1 1 2 2 0 3 0 0 3 0 1 3 1 0 4 0 0
Score : 150 points
Problem Statement
You are given an integer N.
Print all triples of non-negative integers (x,y,z) such that x+y+z\leq N in ascending lexicographical order.
What is lexicographical order for non-negative integer triples?
A triple of non-negative integers (x,y,z) is said to be lexicographically smaller than (x',y',z') if and only if one of the following holds:
- x < x';
- x=x' and y< y';
- x=x' and y=y' and z< z'.
Constraints
- 0 \leq N \leq 21
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print all triples of non-negative integers (x,y,z) such that x+y+z\leq N in ascending lexicographical order, with x,y,z separated by spaces, one triple per line.
Sample Input 1
3
Sample Output 1
0 0 0 0 0 1 0 0 2 0 0 3 0 1 0 0 1 1 0 1 2 0 2 0 0 2 1 0 3 0 1 0 0 1 0 1 1 0 2 1 1 0 1 1 1 1 2 0 2 0 0 2 0 1 2 1 0 3 0 0
Sample Input 2
4
Sample Output 2
0 0 0 0 0 1 0 0 2 0 0 3 0 0 4 0 1 0 0 1 1 0 1 2 0 1 3 0 2 0 0 2 1 0 2 2 0 3 0 0 3 1 0 4 0 1 0 0 1 0 1 1 0 2 1 0 3 1 1 0 1 1 1 1 1 2 1 2 0 1 2 1 1 3 0 2 0 0 2 0 1 2 0 2 2 1 0 2 1 1 2 2 0 3 0 0 3 0 1 3 1 0 4 0 0
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は全 10^9 巻の漫画『すぬけ君』を読むことにしました。
初め、高橋君は『すぬけ君』の単行本を N 冊持っています。i 番目の単行本は a_i 巻です。
高橋君は『すぬけ君』を読み始める前に限り次の操作を 0 回以上何度でも繰り返せます。
- 現在持っている単行本が 1 冊以下の場合、何もしない。そうでない場合、現在持っている単行本から 2 冊を選んで売り、代わりに好きな巻を選んで 1 冊買う
その後、高橋君は『すぬけ君』を 1 巻、2 巻、3 巻、\ldots と順番に読みます。ただし、次に読むべき巻を持っていない状態になった場合、(他の巻を持っているかどうかに関わらず)その時点で『すぬけ君』を読むのをやめます。
高橋君が『すぬけ君』を最大で何巻まで読めるかを求めてください。ただし、1 巻を読めない場合の答えは 0 とします。
制約
- 1 \leq N \leq 3 \times 10^5
- 1 \leq a_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N
出力
答えを出力せよ。
入力例 1
6 1 2 4 6 7 271
出力例 1
4
『すぬけ君』を読み始める前に「7 巻と 271 巻を選んで売り、代わりに 3 巻を選んで 1 冊買う」という内容で操作をすると、高橋君は 1 巻、2 巻、3 巻、4 巻、6 巻を 1 冊ずつ持っている状態になります。
この状態から『すぬけ君』を読み始めると、高橋君は 1 巻、2 巻、3 巻、4 巻を読み、続いて 5 巻を読もうとしますが持っていないためこの時点で『すぬけ君』を読むのをやめます。
操作の方法を変えても 5 巻を読むことは出来ないため、4 が答えです。
入力例 2
10 1 1 1 1 1 1 1 1 1 1
出力例 2
5
高橋君は同じ巻を 2 冊以上持っているかもしれません。
この入力に対しては以下のように 4 回操作をしてから『すぬけ君』を読み始めることで 5 巻まで読むことが出来、これが最大です。
- 1 巻を 2 冊選んで売り、代わりに 2 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 3 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 4 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 5 巻を選んで 1 冊買う
入力例 3
1 5
出力例 3
0
高橋君は 1 巻を読めません。
Score : 300 points
Problem Statement
Takahashi is going to read a manga series "Snuke-kun" in 10^9 volumes.
Initially, Takahashi has N books of this series. The i-th book is Volume a_i.
Takahashi may repeat the following operation any number of (possibly zero) times only before he begins to read:
- Do nothing if he has 1 or less books; otherwise, sell two of the books he has and buy one book of any volume instead.
Then, Takahashi reads Volume 1, Volume 2, Volume 3, \ldots, in order. However, when he does not have a book of the next volume to read, he stops reading the series (regardless of the other volumes he has).
Find the latest volume of the series that he can read up to. If he cannot read any, let the answer be 0.
Constraints
- 1 \leq N \leq 3 \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 \ldots a_N
Output
Print the answer.
Sample Input 1
6 1 2 4 6 7 271
Sample Output 1
4
Before he begins to read the series, he may do the following operation: "sell books of Volumes 7 and 271 and buy one book of Volume 3 instead." Then, he has one book each of Volumes 1, 2, 3, 4, and 6.
If he then begins to read the series, he reads Volumes 1, 2, 3, and 4, then tries to read Volume 5. However, he does not have one, so he stops reading at this point.
Regardless of the choices in the operation, he cannot read Volume 5, so the answer is 4.
Sample Input 2
10 1 1 1 1 1 1 1 1 1 1
Sample Output 2
5
Takahashi may have multiple books of the same volume.
For this input, if he performs the following 4 operations before he begins to read the series, he can read up to Volume 5, which is the maximum:
- Sell two books of Volume 1 and buy a book of Volume 2 instead.
- Sell two books of Volume 1 and buy a book of Volume 3 instead.
- Sell two books of Volume 1 and buy a book of Volume 4 instead.
- Sell two books of Volume 1 and buy a book of Volume 5 instead.
Sample Input 3
1 5
Sample Output 3
0
Takahashi cannot read Volume 1.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は数直線上の座標 0 の位置にいます。
これから高橋君は N 回のジャンプを行います。i \, (1 \leq i \leq N) 回目のジャンプでは、正の方向に a_i または b_i 移動します。
N 回のジャンプの後に座標 X の位置にいるようにすることはできますか?
制約
- 1 \leq N \leq 100
- 1 \leq a_i \lt b_i \leq 100 \, (1 \leq i \leq N)
- 1 \leq X \leq 10000
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N X a_1 b_1 \vdots a_N b_N
出力
N 回のジャンプの後に座標 X の位置にいるようにすることができるならば Yes と、そうでないなら No と出力せよ。
入力例 1
2 10 3 6 4 5
出力例 1
Yes
1 回目のジャンプでは b_1 (= 6) 移動し、2 回目のジャンプでは a_2 (= 4) 移動することで、座標 X (= 10) の位置にいるようにすることができます。
入力例 2
2 10 10 100 10 100
出力例 2
No
1 回目のジャンプの後に座標 X (= 10) の位置にいるようにすることはできますが、全てのジャンプの後に座標 X (= 10) の位置にいるようにすることはできません。
入力例 3
4 12 1 8 5 7 3 4 2 6
出力例 3
Yes
Score : 300 points
Problem Statement
Takahashi is standing at the coordinate 0 on a number line.
He will now perform N jumps. In the i-th jump (1 \leq i \leq N), he moves a_i or b_i in the positive direction.
Is it possible for him to be at the coordinate X after N jumps?
Constraints
- 1 \leq N \leq 100
- 1 \leq a_i \lt b_i \leq 100 \, (1 \leq i \leq N)
- 1 \leq X \leq 10000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X a_1 b_1 \vdots a_N b_N
Output
If it is possible for Takahashi to be at the coordinate X after N jumps, print Yes; otherwise, print No.
Sample Input 1
2 10 3 6 4 5
Sample Output 1
Yes
By moving b_1 (= 6) in the first jump and a_2 (= 4) in the second jump, he can be at the coordinate X (= 10).
Sample Input 2
2 10 10 100 10 100
Sample Output 2
No
He can be at the coordinate X (= 10) after the first jump, but not after all jumps.
Sample Input 3
4 12 1 8 5 7 3 4 2 6
Sample Output 3
Yes
Time Limit: 2.5 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
座標平面上に 1 から N の番号がついた N 人の人がいます。
人 1 は原点にいます。
次の形式の情報が M 個与えられます。
- 人 A_i から見て、人 B_i は、x 軸正方向に X_i、y 軸正方向に Y_i 離れた位置にいる
それぞれの人がいる座標を求めてください。一意に定まらないときはそのことを報告してください。
制約
- 1 \leq N \leq 2\times 10^5
- 0 \leq M \leq 2\times 10^5
- 1\leq A_i, B_i \leq N
- A_i \neq B_i
- -10^9 \leq X_i,Y_i \leq 10^9
- 入力は全て整数である
- 与えられる情報は矛盾しない
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 X_1 Y_1 \vdots A_M B_M X_M Y_M
出力
N 行出力せよ。
人 i のいる座標が一意に定まらないとき、i 行目には undecidable と出力せよ。
人 i のいる座標が (s_i,t_i) と一意に定まるとき、i 行目には s_i,t_i をこの順に空白区切りで出力せよ。
入力例 1
3 2 1 2 2 1 1 3 -1 -2
出力例 1
0 0 2 1 -1 -2
3 人の位置関係は下図のようになっています。

入力例 2
3 2 2 1 -2 -1 2 3 -3 -3
出力例 2
0 0 2 1 -1 -2
3 人の位置関係は下図のようになっています。

入力例 3
5 7 1 2 0 0 1 2 0 0 2 3 0 0 3 1 0 0 2 1 0 0 3 2 0 0 4 5 0 0
出力例 3
0 0 0 0 0 0 undecidable undecidable
同じ情報が複数回与えられたり、同じ座標に複数の人がいることもあります。
Score : 400 points
Problem Statement
There are N people numbered 1 to N on a coordinate plane.
Person 1 is at the origin.
You are given M pieces of information in the following form:
- From person A_i's perspective, person B_i is X_i units away in the positive x-direction and Y_i units away in the positive y-direction.
Determine the coordinates of each person. If the coordinates of a person cannot be uniquely determined, report that fact.
Constraints
- 1 \leq N \leq 2\times 10^5
- 0 \leq M \leq 2\times 10^5
- 1\leq A_i, B_i \leq N
- A_i \neq B_i
- -10^9 \leq X_i,Y_i \leq 10^9
- All input values are integers.
- The given information is consistent.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 X_1 Y_1 \vdots A_M B_M X_M Y_M
Output
Print N lines.
If the coordinates of person i cannot be uniquely determined, the i-th line should contain undecidable.
If they can be uniquely determined as (s_i,t_i), the i-th line should contain s_i and t_i in this order, separated by a space.
Sample Input 1
3 2 1 2 2 1 1 3 -1 -2
Sample Output 1
0 0 2 1 -1 -2
The figure below shows the positional relationship of the three people.

Sample Input 2
3 2 2 1 -2 -1 2 3 -3 -3
Sample Output 2
0 0 2 1 -1 -2
The figure below shows the positional relationship of the three people.

Sample Input 3
5 7 1 2 0 0 1 2 0 0 2 3 0 0 3 1 0 0 2 1 0 0 3 2 0 0 4 5 0 0
Sample Output 3
0 0 0 0 0 0 undecidable undecidable
The same piece of information may be given multiple times, and multiple people may be at the same coordinates.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
正整数 X, Y に対し、2 次元平面上において以下の条件を満たす長方形を良い長方形と呼びます。
- 全ての辺は x 軸または y 軸に平行である。
- 全ての頂点に対し、その x 座標は 0 以上 X 以下の整数であり、その y 座標は 0 以上 Y 以下の整数である。
面積がそれぞれ A 以上、B 以上、C 以上であるような 3 つの良い長方形を重ならないように配置することができるか判定してください。
ただし、3 つの長方形が重ならないとは、どの 2 つの長方形についても、それらの共通部分の面積が 0 であることを指します。
制約
- 1 \leq X, Y \leq 10^9
- 1 \leq A, B, C \leq 10^{18}
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
X Y A B C
出力
問題文で与えられた条件を満たすように長方形を配置することができるならば Yes、できないならば No と出力せよ。
入力例 1
3 3 2 2 3
出力例 1
Yes
下の図のように配置すればよいです。長方形内の数値は面積を表します。
2 \geq A, 3 \geq B, 3 \geq C であるので、問題文で与えられた条件を満たします。

入力例 2
3 3 4 4 1
出力例 2
No
条件を満たすように配置することはできません。
入力例 3
1000000000 1000000000 1000000000000000000 1000000000000000000 1000000000000000000
出力例 3
No
Score : 500 points
Problem Statement
For positive integers X and Y, a rectangle in a two-dimensional plane that satisfies the conditions below is said to be good.
- Every edge is parallel to the x- or y-axis.
- For every vertex, its x-coordinate is an integer between 0 and X (inclusive), and y-coordinate is an integer between 0 and Y (inclusive).
Determine whether it is possible to place the following three good rectangles without overlapping: a good rectangle of an area at least A, another of an area at least B, and another of an area at least C.
Here, three rectangles are considered to be non-overlapping when the intersection of any two of them has an area of 0.
Constraints
- 1 \leq X, Y \leq 10^9
- 1 \leq A, B, C \leq 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y A B C
Output
If it is possible to place three rectangles under the conditions specified in the Problem Statement, print Yes; otherwise, print No.
Sample Input 1
3 3 2 2 3
Sample Output 1
Yes
The figure below shows a possible placement, where the number in a rectangle represents its area.
We can see that 2 \geq A, 3 \geq B, 3 \geq C, satisfying the conditions.

Sample Input 2
3 3 4 4 1
Sample Output 2
No
There is no possible placement under the conditions.
Sample Input 3
1000000000 1000000000 1000000000000000000 1000000000000000000 1000000000000000000
Sample Output 3
No
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
2 以上の整数 N が与えられます。下記の条件を満たす 2 以上の整数 b の個数を出力してください。
- N を b 進法で表記したとき、すべての桁について「その桁が 0 または 1 である」が成り立つ。
T 個の独立なテストケースについて答えを求めてください。
なお、本問題の制約下において、上記の「条件を満たす 2 以上の整数 b の個数」は有限であることが証明できます。
制約
- 1 \leq T \leq 1000
- 2 \leq N \leq 10^{18}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。ここで、\mathrm{test}_i は i 番目のテストケースを表す。
T
\mathrm{test}_1
\mathrm{test}_2
\vdots
\mathrm{test}_T
各テストケースは以下の形式で与えられる。
N
出力
T 行出力せよ。 i = 1, 2, \ldots, T について、i 行目には i 番目のテストケースに対する答えを出力せよ。
入力例 1
3 12 2 36
出力例 1
4 1 5
1 番目のテストケースについて、問題文中の条件を満たす b は、b = 2, 3, 11, 12 の 4 つです。 実際、N = 12 を 2, 3, 11, 12 進法で表すと、それぞれ 1100, 110, 11, 10 となります。
Score : 500 points
Problem Statement
Given an integer N not less than 2, find the number of integers b not less than 2 such that:
- when N is written in base b, every digit is 0 or 1.
Find the answer for T independent test cases.
It can be proved that there is a finite number of desired integers b not less than 2 under the constraints of this problem.
Constraints
- 1 \leq T \leq 1000
- 2 \leq N \leq 10^{18}
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where \mathrm{test}_i denotes the i-th test case:
T
\mathrm{test}_1
\mathrm{test}_2
\vdots
\mathrm{test}_T
Each test case is given in the following format:
N
Output
Print T lines. For i = 1, 2, \ldots, T, the i-th line should contain the answer to the i-th test case.
Sample Input 1
3 12 2 36
Sample Output 1
4 1 5
For the first test case, four b's satisfy the condition in the problem statement: b = 2, 3, 11, 12. Indeed, when N=12 is written in base 2, 3, 11, and 12, it becomes 1100, 110, 11 and 10, respectively.