Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字のみからなる長さ 3 の文字列 S が与えられます。
S の各文字を並び替えて得られる文字列は、何種類ありますか?
制約
- S は英小文字のみからなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の各文字を並び替えて得られる文字列の種類数を出力せよ。
入力例 1
aba
出力例 1
3
S= aba
の各文字を並び替えて得られる文字列は、aab
, aba
, baa
の 3 通りです。
入力例 2
ccc
出力例 2
1
S= ccc
の各文字を並び替えて得られる文字列は、ccc
の 1 通りのみです。
入力例 3
xyz
出力例 3
6
S= xyz
の各文字を並び替えて得られる文字列は、xyz
, xzy
, yxz
, yzx
, zxy
, zyx
の 6 通りです。
Score : 100 points
Problem Statement
You are given a string S of length 3 consisting of lowercase English letters.
How many different strings can be obtained by permuting the characters in S?
Constraints
- S is a string S of length 3 consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of different strings that can be obtained by permuting the characters in S.
Sample Input 1
aba
Sample Output 1
3
By permuting the characters in S= aba
, three different strings can be obtained: aab
, aba
, baa
.
Sample Input 2
ccc
Sample Output 2
1
By permuting the characters in S= ccc
, just one string can be obtained: ccc
.
Sample Input 3
xyz
Sample Output 3
6
By permuting the characters in S= xyz
, six different strings can be obtained: xyz
, xzy
, yxz
, yzx
, zxy
, zyx
.
Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋くんは回転寿司で N 皿の料理を食べました。 i 皿目の色は文字列 C_i で表されます。
また、料理の価格は皿の色と対応し、 i=1,\ldots,M のそれぞれについて、色が文字列 D_i の皿の料理は一皿 P_i 円です。また、D_1,\ldots,D_M のいずれとも異なる色の皿の料理は一皿 P_0 円です。
高橋くんが食べた料理の価格の合計を求めてください。
制約
- 1\leq N,M\leq 100
- C_i,D_i は英小文字からなる長さ 1 以上 20 以下の文字列
- D_1,\ldots,D_M はすべて異なる
- 1\leq P_i\leq 10000
- N,M,P_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N M C_1 \ldots C_N D_1 \ldots D_M P_0 P_1 \ldots P_M
出力
答えを整数として出力せよ。
入力例 1
3 2 red green blue blue red 800 1600 2800
出力例 1
5200
blue
の皿は P_1 = 1600 円、red
の皿は P_2 = 2800 円、green
の皿は P_0 = 800 円です。
高橋くんが食べた料理の価格の合計は、2800+800+1600=5200 円です。
入力例 2
3 2 code queen atcoder king queen 10 1 1
出力例 2
21
Score : 200 points
Problem Statement
Takahashi ate N plates of sushi at a sushi restaurant. The color of the i-th plate is represented by a string C_i.
The price of a sushi corresponds to the color of the plate. For each i=1,\ldots,M, the sushi on a plate whose color is represented by a string D_i is worth P_i yen a plate (yen is the currency of Japan). If the color does not coincide with any of D_1,\ldots, and D_M, it is worth P_0 yen a plate.
Find the total amount of the prices of sushi that Takahashi ate.
Constraints
- 1\leq N,M\leq 100
- C_i and D_i are strings of length between 1 and 20, inclusive, consisting of lowercase English letters.
- D_1,\ldots, and D_M are distinct.
- 1\leq P_i\leq 10000
- N, M, and P_i are integers.
Input
The input is given from Standard Input in the following format:
N M C_1 \ldots C_N D_1 \ldots D_M P_0 P_1 \ldots P_M
Output
Print the answer as an integer.
Sample Input 1
3 2 red green blue blue red 800 1600 2800
Sample Output 1
5200
A blue
plate, red
plate, and green
plate are worth P_1 = 1600, P_2 = 2800, and P_0 = 800 yen, respectively.
The total amount of the prices of the sushi that he ate is 2800+800+1600=5200 yen.
Sample Input 2
3 2 code queen atcoder king queen 10 1 1
Sample Output 2
21
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
H 行 W 列のグリッドがあり、はじめすべてのマスが白で塗られています。グリッドの上から i 行目、左から j 列目のマスを (i, j) と表記します。
このグリッドはトーラス状であるとみなします。すなわち、各 1 \leq i \leq H に対して (i, W) の右に (i, 1) があり、各 1 \leq j \leq W に対して (H, j) の下に (1, j) があるとします。
高橋君が (1, 1) にいて上を向いています。高橋君が以下の操作を N 回繰り返した後のグリッドの各マスがどの色で塗られているか出力してください。
- 現在いるマスが白で塗られている場合は、現在いるマスを黒に塗り替え、時計回りに 90^\circ 回転し、向いている方向に 1 マス進む。そうでない場合は、現在いるマスを白に塗り替え、反時計回りに 90^\circ 回転し、向いている方向に 1 マス進む。
制約
- 1 \leq H, W \leq 100
- 1 \leq N \leq 1000
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W N
出力
H 行出力せよ。i 行目には長さ W の文字列であって、(i, j) が白で塗られている場合は j 文字目が .
、黒で塗られている場合は j 文字目が #
であるものを出力せよ。
入力例 1
3 4 5
出力例 1
.#.. ##.. ....
グリッドの各マスは操作によって以下のように変化します。
.... #... ##.. ##.. ##.. .#.. .... → .... → .... → .#.. → ##.. → ##.. .... .... .... .... .... ....
入力例 2
2 2 1000
出力例 2
.. ..
入力例 3
10 10 10
出力例 3
##........ ##........ .......... .......... .......... .......... .......... .......... .......... #........#
Score: 250 points
Problem Statement
There is a grid with H rows and W columns; initially, all cells are painted white. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left.
This grid is considered to be toroidal. That is, (i, 1) is to the right of (i, W) for each 1 \leq i \leq H, and (1, j) is below (H, j) for each 1 \leq j \leq W.
Takahashi is at (1, 1) and facing upwards. Print the color of each cell in the grid after Takahashi repeats the following operation N times.
- If the current cell is painted white, repaint it black, rotate 90^\circ clockwise, and move forward one cell in the direction he is facing. Otherwise, repaint the current cell white, rotate 90^\circ counterclockwise, and move forward one cell in the direction he is facing.
Constraints
- 1 \leq H, W \leq 100
- 1 \leq N \leq 1000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W N
Output
Print H lines. The i-th line should contain a string of length W where the j-th character is .
if the cell (i, j) is painted white, and #
if it is painted black.
Sample Input 1
3 4 5
Sample Output 1
.#.. ##.. ....
The cells of the grid change as follows due to the operations:
.... #... ##.. ##.. ##.. .#.. .... → .... → .... → .#.. → ##.. → ##.. .... .... .... .... .... ....
Sample Input 2
2 2 1000
Sample Output 2
.. ..
Sample Input 3
10 10 10
Sample Output 3
##........ ##........ .......... .......... .......... .......... .......... .......... .......... #........#
Time Limit: 2 sec / Memory Limit: 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
0
and1
. - 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.