実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君は野球ゲームを作っています。
高橋君はバッターの打率を指定された桁数の分だけ表示するプログラムを作ることにしました。
整数 A, B があります。ここで A, B は 1 \leq A \leq 10, 0 \leq B \leq A を満たします。
このとき、文字列 S を次のように定義します。
- \dfrac{B}{A} を小数点第 4 位で四捨五入した値を「整数部 1 桁」「
.」「小数部 3 桁」の順に末尾ゼロを省略せずに表記した文字列。
例えば A=7, B = 4 の場合は、\dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots で、これを小数点第 4 位で四捨五入した値は 0.571 です。よって S は 0.571 になります。
A, B が入力として与えられるので S を出力してください。
制約
- 1 \leq A \leq 10
- 0 \leq B \leq A
- A, B は整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
S を問題文の指示に従った形式で出力せよ。問題文の指示と異なる形式で出力した場合は誤答となることに注意せよ。
入力例 1
7 4
出力例 1
0.571
問題文本文でも説明した通り、\dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots で、これを小数点第 4 位で四捨五入した値は 0.571 です。よって S は 0.571 になります。
入力例 2
7 3
出力例 2
0.429
\dfrac{B}{A} = \dfrac{3}{7} = 0.428571\dots で、これを小数点第 4 位で四捨五入した値は 0.429 です。(繰り上がりが発生するのに注意してください。)
よって S は 0.429 となります。
入力例 3
2 1
出力例 3
0.500
\dfrac{B}{A} = \dfrac{1}{2} = 0.5 で、これを小数点第 4 位で四捨五入した値も同様に 0.5 です。
よって S は 0.500 となります。小数部を 3 桁並べる必要があるのに注意してください。
入力例 4
10 10
出力例 4
1.000
入力例 5
1 0
出力例 5
0.000
Score : 100 points
Problem Statement
Takahashi is making a computer baseball game.
He will write a program that shows a batter's batting average with a specified number of digits.
There are integers A and B, which satisfy 1 \leq A \leq 10 and 0 \leq B \leq A.
Let S be the string obtained as follows.
- Round off \dfrac{B}{A} to three decimal digits, then write the integer part (1 digit),
.(the decimal point), and the decimal part (3 digits) in this order, with trailing zeros.
For example, if A=7 and B=4, then \dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots rounded off to three decimal digits is 0.571. Thus, S is 0.571.
You are given A and B as the input and asked to print S.
Constraints
- 1 \leq A \leq 10
- 0 \leq B \leq A
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print S in the format specified in the Problem Statement. Note that answers in different formats will be considered wrong.
Sample Input 1
7 4
Sample Output 1
0.571
As explained in the Problem Statement, \dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots rounded off to three decimal digits is 0.571. Thus, S is 0.571.
Sample Input 2
7 3
Sample Output 2
0.429
\dfrac{B}{A} = \dfrac{3}{7} = 0.428571\dots rounded off to three decimal digits is 0.429. (Note that it got rounded up.)
Thus, S is 0.429.
Sample Input 3
2 1
Sample Output 3
0.500
\dfrac{B}{A} = \dfrac{1}{2} = 0.5 rounded off to three decimal digits is again 0.5.
Thus, S is 0.500. Note that it must have three decimal places.
Sample Input 4
10 10
Sample Output 4
1.000
Sample Input 5
1 0
Sample Output 5
0.000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
5 枚のカードがあり、それぞれのカードには整数 A,B,C,D,E が書かれています。
この 5 枚組は以下の条件を満たすとき、またそのときに限って、フルハウスであると呼ばれます。
- 同じ数が書かれたカード 3 枚と、別の同じ数が書かれたカード 2 枚からなる。
5 枚組がフルハウスであるか判定してください。
制約
- 1 \leq A,B,C,D,E\leq 13
- A,B,C,D,E 全てが同じ値ではない
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E
出力
フルハウスである場合 Yes を、そうでないとき No を出力せよ。
入力例 1
1 2 1 2 1
出力例 1
Yes
1 が書かれたカード 3 枚と、2 が書かれたカード 2 枚からなるため、これはフルハウスです。
入力例 2
12 12 11 1 2
出力例 2
No
フルハウスの条件を満たしません。
Score : 100 points
Problem Statement
We have five cards with integers A, B, C, D, and E written on them, one on each card.
This set of five cards is called a Full house if and only if the following condition is satisfied:
- the set has three cards with a same number written on them, and two cards with another same number written on them.
Determine whether the set is a Full house.
Constraints
- 1 \leq A,B,C,D,E\leq 13
- Not all of A, B, C, D, and E are the same.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E
Output
If the set is a Full house, print Yes; otherwise, print No.
Sample Input 1
1 2 1 2 1
Sample Output 1
Yes
The set has three cards with 1 written on them and two cards with 2 written on them, so it is a Full house.
Sample Input 2
12 12 11 1 2
Sample Output 2
No
The condition is not satisfied.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君はゲームの中で洞窟を探索しています。
洞窟は N 個の部屋が一列に並んだ構造であり、入り口から順に部屋 1,2,\ldots,N と番号がついています。
最初、高橋君は部屋 1 におり、持ち時間 は T です。
各 1 \leq i \leq N-1 について、持ち時間を A_i 消費することで、部屋 i から部屋 i+1 へ移動することができます。これ以外に部屋を移動する方法はありません。
また、持ち時間が 0 以下になるような移動は行うことができません。
洞窟内には M 個のボーナス部屋があります。i 番目のボーナス部屋は部屋 X_i であり、この部屋に到達すると持ち時間が Y_i 増加します。
高橋君は部屋 N にたどりつくことができますか?
制約
- 2 \leq N \leq 10^5
- 0 \leq M \leq N-2
- 1 \leq T \leq 10^9
- 1 \leq A_i \leq 10^9
- 1 < X_1 < \ldots < X_M < N
- 1 \leq Y_i \leq 10^9
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M T
A_1 A_2 \ldots A_{N-1}
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M
出力
高橋君が部屋 N にたどりつくことができるなら Yes を、できないなら No を出力せよ。
入力例 1
4 1 10 5 7 5 2 10
出力例 1
Yes
- 高橋君は最初、部屋 1 にいて持ち時間は 10 です。
- 持ち時間を 5 消費して部屋 2 に移動します。持ち時間は 5 になります。その後、持ち時間が 10 増え 15 になります。
- 持ち時間を 7 消費して部屋 3 に移動します。持ち時間は 8 になります。
- 持ち時間を 5 消費して部屋 4 に移動します。持ち時間は 3 になります。
入力例 2
4 1 10 10 7 5 2 10
出力例 2
No
部屋 1 から部屋 2 へ移動することができません。
Score : 200 points
Problem Statement
Takahashi is exploring a cave in a video game.
The cave consists of N rooms arranged in a row. The rooms are numbered Room 1,2,\ldots,N from the entrance.
Takahashi is initially in Room 1, and the time limit is T.
For each 1 \leq i \leq N-1, he may consume a time of A_i to move from Room i to Room (i+1). There is no other way to move between rooms.
He cannot make a move that makes the time limit 0 or less.
There are M bonus rooms in the cave. The i-th bonus room is Room X_i; when he arrives at the room, the time limit increases by Y_i.
Can Takahashi reach Room N?
Constraints
- 2 \leq N \leq 10^5
- 0 \leq M \leq N-2
- 1 \leq T \leq 10^9
- 1 \leq A_i \leq 10^9
- 1 < X_1 < \ldots < X_M < N
- 1 \leq Y_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M T
A_1 A_2 \ldots A_{N-1}
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M
Output
If Takahashi can reach Room N, print Yes; otherwise, print No.
Sample Input 1
4 1 10 5 7 5 2 10
Sample Output 1
Yes
- Takahashi is initially in Room 1, and the time limit is 10.
- He consumes a time of 5 to move to Room 2. Now the time limit is 5. Then, the time limit increases by 10; it is now 15.
- He consumes a time of 7 to move to Room 3. Now the time limit is 8.
- He consumes a time of 5 to move to Room 4. Now the time limit is 3.
Sample Input 2
4 1 10 10 7 5 2 10
Sample Output 2
No
He cannot move from Room 1 to Room 2.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
縦 R 行横 C 列の盤面があります。上から i 行目、左から j 列目のマスを (i,j) と表します。
(i,j) の現在の状態が文字 B_{i,j} として与えられます。
. は空きマス、# は壁があるマスを表し、
1, 2,\dots, 9 はそれぞれ威力 1,2,\dots,9 の爆弾があるマスを表します。
次の瞬間に、全ての爆弾が同時に爆発します。 爆弾が爆発すると、爆弾があるマスからのマンハッタン距離がその爆弾の威力以下であるような全てのマス(その爆弾があるマス自体を含む)が空きマスに変わります。 ここで、(r_1,c_1) から (r_2,c_2) までのマンハッタン距離は |r_1-r_2|+|c_1-c_2| です。
爆発後の盤面を出力してください。
制約
- 1\leq R,C \leq 20
- R,C は整数
- B_{i,j} は
.,#,1,2,\dots,9のいずれかである
入力
入力は以下の形式で標準入力から与えられる。
R C
B_{1,1}B_{1,2}\dots B_{1,C}
\vdots
B_{R,1}B_{R,2}\dots B_{R,C}
出力
爆発後の盤面を R 行で出力せよ。盤面の表し方は入力と同じ形式を用いること (R と C を出力する必要はない)。
入力例 1
4 4 .1.# ###. .#2. #.##
出力例 1
...# #... .... #...

- (1,2) にある爆弾の爆発によって、上図の青いマスと紫のマスが空きマスに変わります。
- (3,3) にある爆弾の爆発によって、上図の赤いマスと紫のマスが空きマスに変わります。
この例のように、爆弾が効果を及ぼす範囲に被りがあることもあります。
入力例 2
2 5 ..#.# ###.#
出力例 2
..#.# ###.#
爆弾が 1 つもないこともあります。
入力例 3
2 3 11# ###
出力例 3
... ..#
入力例 4
4 6 #.#3#. ###.#. ##.### #1..#.
出力例 4
...... #..... #....# ....#.
Score : 200 points
Problem Statement
We have a board with R rows running horizontally and C columns running vertically. Let (i,j) denote the square at the i-th row from the top and j-th column from the left.
You are given characters B_{i,j} representing the current states of (i,j).
. represents an empty square; # represents a square with a wall; 1, 2,\dots, 9 represent a square with a bomb of power 1,2,\dots,9, respectively.
At the next moment, all bombs will explode simultaneously. When a bomb explodes, every square whose Manhattan distance from the square with the bomb is not greater than the power of the bomb will turn into an empty square. Here, the Manhattan distance from (r_1,c_1) to (r_2,c_2) is |r_1-r_2|+|c_1-c_2|.
Print the board after the explosions.
Constraints
- 1\leq R,C \leq 20
- R and C are integers.
- Each B_{i,j} is one of
.,#,1,2, \dots,9.
Input
The input is given from Standard Input in the following format:
R C
B_{1,1}B_{1,2}\dots B_{1,C}
\vdots
B_{R,1}B_{R,2}\dots B_{R,C}
Output
Print R lines representing the board after the explosions. Use the format used in the input (do not print R or C).
Sample Input 1
4 4 .1.# ###. .#2. #.##
Sample Output 1
...# #... .... #...

- The explosion of the bomb at (1,2) will turn the blue squares and purple squares in the above figure into empty squares.
- The explosion of the bomb at (3,3) will turn the red squares and purple squares in the above figure into empty squares.
As seen in this sample, the explosion ranges of bombs may overlap.
Sample Input 2
2 5 ..#.# ###.#
Sample Output 2
..#.# ###.#
There may be no bombs.
Sample Input 3
2 3 11# ###
Sample Output 3
... ..#
Sample Input 4
4 6 #.#3#. ###.#. ##.### #1..#.
Sample Output 4
...... #..... #....# ....#.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
子供と大人があわせて N 人います。i 番目の人の体重は W_i です。
それぞれの人が子供か大人かは、0 と 1 からなる長さ N の文字列 S によって表され、
S の i 文字目が 0 であるとき i 番目の人が子供であることを、1 であるとき i 番目の人が大人であることをさします。
ロボットである高橋君に対して実数 X を設定すると、
高橋君はそれぞれの人に対して、体重が X 未満なら子供、X 以上なら大人と判定します。
実数 X に対してf(X) を、高橋君に X を設定したときに N 人のうち子供か大人かを正しく判定できる人数で定めます。
X が実数全体を動くとき、f(X) の最大値を求めてください。
制約
- 1\leq N\leq 2\times 10^5
- S は
0と1からなる長さ N の文字列 - 1\leq W_i\leq 10^9
- N,W_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N S W_1 W_2 \ldots W_N
出力
f(X) の最大値を整数で一行に出力せよ。
入力例 1
5 10101 60 45 30 40 80
出力例 1
4
X=50 と設定すると、高橋君は 2,3,4 番目の人を子供、 1,5 番目の人を大人と判定します。
実際には 2,4 番目の人が子供、 1,3,5 番目の人が大人であるので、このとき、1,2,4,5 番目の合計 4 人に対して正しく判定できています。
よって、f(50)=4 です。
5 人全員に対して正しく判定できるような X は存在しないのでこのときが最大です。よって、4 を出力します。
入力例 2
3 000 1 2 3
出力例 2
3
例えば、X=10 とすると最大値 f(10)=3 を達成します。
全員が大人、または全員が子供である可能性もあることに注意してください。
入力例 3
5 10101 60 50 50 50 60
出力例 3
4
例えば、X=55 とすると最大値 f(55)=4 を達成します。
同じ体重の人が複数人存在する可能性もあることに注意してください。
Score : 300 points
Problem Statement
There are N people, each of whom is either a child or an adult. The i-th person has a weight of W_i.
Whether each person is a child or an adult is specified by a string S of length N consisting of 0 and 1.
If the i-th character of S is 0, then the i-th person is a child; if it is 1, then the i-th person is an adult.
When Takahashi the robot is given a real number X,
Takahashi judges a person with a weight less than X to be a child and a person with a weight more than or equal to X to be an adult.
For a real value X, let f(X) be the number of people whom Takahashi correctly judges whether they are children or adults.
Find the maximum value of f(X) for all real values of X.
Constraints
- 1\leq N\leq 2\times 10^5
- S is a string of length N consisting of
0and1. - 1\leq W_i\leq 10^9
- N and W_i are integers.
Input
Input is given from Standard Input in the following format:
N S W_1 W_2 \ldots W_N
Output
Print the maximum value of f(X) as an integer in a single line.
Sample Input 1
5 10101 60 45 30 40 80
Sample Output 1
4
When Takahashi is given X=50, it judges the 2-nd, 3-rd, and 4-th people to be children and the 1-st and 5-th to be adults.
In reality, the 2-nd and 4-th are children, and the 1-st, 3-rd, and 5-th are adults, so the 1-st, 2-nd, 4-th, and 5-th people are correctly judged.
Thus, f(50)=4.
This is the maximum since there is no X that judges correctly for all 5 people. Thus, 4 should be printed.
Sample Input 2
3 000 1 2 3
Sample Output 2
3
For example, X=10 achieves the maximum value f(10)=3.
Note that the people may be all children or all adults.
Sample Input 3
5 10101 60 50 50 50 60
Sample Output 3
4
For example, X=55 achieves the maximum value f(55)=4.
Note that there may be multiple people with the same weight.