Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
チェス盤のどこにコマが置かれているか答えてください。
縦 8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。
- 左から 1 列目にあるマスの名前の 1 文字目は
aである。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目はb,c,d,e,f,g,hである。 - 下から 1 行目にあるマスの名前の 2 文字目は
1である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は2,3,4,5,6,7,8である。
例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。
グリッドの状態を表す長さ 8 の 8 つの文字列 S_1,\ldots,S_8 が与えられます。
S_i の j 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。
制約
- S_i は
.および*のみからなる長さ 8 の文字列である - S_1,\ldots,S_8 の中に文字
*はちょうど 1 つ存在する。
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
出力
答えを出力せよ。
入力例 1
........ ........ ........ ........ ........ ........ ........ *.......
出力例 1
a1
問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。
入力例 2
........ ........ ........ ........ ........ .*...... ........ ........
出力例 2
b3
Score : 200 points
Problem Statement
Locate a piece on a chessboard.
We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.
- The first character of the name of a square in the 1-st column from the left is
a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left isb,c,d,e,f,g,h, respectively. - The second character of the name of a square in the 1-st row from the bottom is
1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is2,3,4,5,6,7,8, respectively.
For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.
You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise.
The character * occurs exactly once among S_1,\ldots,S_8.
Find the name of the square that has a piece on it.
Constraints
- S_i is a string of length 8 consisting of
.and*. - The character
*occurs exactly once among S_1,\ldots,S_8.
Input
The input is given from Standard Input in the following format:
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
Output
Print the answer.
Sample Input 1
........ ........ ........ ........ ........ ........ ........ *.......
Sample Output 1
a1
As explained in the problem statement, the bottom-left square is named a1.
Sample Input 2
........ ........ ........ ........ ........ .*...... ........ ........
Sample Output 2
b3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は体操の大会に参加しています。
大会では、5N 人の審査員それぞれが高橋君の演技に対して評点をつけ、それらを元に次のように高橋君の得点が決定されます。
- 高い評点をつけた方から順に N 人の審査員による評点を無効にする。
- 低い評点をつけた方から順に N 人の審査員による評点を無効にする。
- 残りの 3N 人の審査員による評点の平均点を高橋君の得点とする。
より厳密には、審査員がつけた得点の多重集合 S (|S|=5N) に対して次の操作を行って得られたものが高橋君の得点となります。
- 「S の最大の要素(複数ある場合はそのうちの 1 つ)を選び、S から取り除く」という操作を N 回繰り返す。
- 「S の最小の要素(複数ある場合はそのうちの 1 つ)を選び、S から取り除く」という操作を N 回繰り返す。
- S に残った 3N 個の要素の平均を高橋君の得点とする。
高橋君の演技に対する、i 人目 (1\leq i\leq 5N) の審査員の評点は X_i 点でした。 高橋君の得点を計算してください。
制約
- 1\leq N\leq 100
- 0\leq X_i\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
X_1 X_2 \ldots X_{5N}
出力
高橋君の得点を出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-5} 以下であれば正解として扱われる。
入力例 1
1 10 100 20 50 30
出力例 1
33.333333333333336
N=1 であるので、評点が高い方と低い方からそれぞれ 1 人ずつの審査員による評点を無効にします。
1 番高い評点をつけた審査員は 2 人目 (100 点) であるため、これを無効にします。
また、1 番低い評点をつけた審査員は 1 人目 (10 点) であるため、これも無効にします。
よって、最終的な平均点は \displaystyle\frac{20+50+30}{3}=33.333\cdots となります。
出力は、真の値との絶対誤差または相対誤差が 10^{-5} 以下であれば正解として扱われる事に注意してください。
入力例 2
2 3 3 3 4 5 6 7 8 99 100
出力例 2
5.500000000000000
N=2 であるので、評点が高い方と低い方からそれぞれ 2 人ずつの審査員による評点を無効にします。
1,2 番目に高い評点をつけた審査員は順に 10 人目 (100 点), 9 人目 (99 点) であるため、これを無効にします。
1 番低い評点をつけた審査員は 1,2,3 人目 (3 点) の 3 人がいるため、このうち 2 人を無効とします。
よって、答えは \displaystyle\frac{3+4+5+6+7+8}{6}=5.5 となります。
1 番低い評点をつけた 3 人のうちどの 2 人を無効にしたかは、答えに影響しない事に注意してください。
Score : 200 points
Problem Statement
Takahashi is participating in a gymnastic competition.
In the competition, each of 5N judges grades Takahashi's performance, and his score is determined as follows:
- Invalidate the grades given by the N judges who gave the highest grades.
- Invalidate the grades given by the N judges who gave the lowest grades.
- Takahashi's score is defined as the average of the remaining 3N judges' grades.
More formally, Takahashi's score is obtained by performing the following procedure on the multiset of the judges' grades S (|S|=5N):
- Repeat the following operation N times: choose the maximum element (if there are multiple such elements, choose one of them) and remove it from S.
- Repeat the following operation N times: choose the minimum element (if there are multiple such elements, choose one of them) and remove it from S.
- Takahashi's score is defined as the average of the 3N elements remaining in S.
The i-th (1\leq i\leq 5N) judge's grade for Takahashi's performance was X_i points. Find Takahashi's score.
Constraints
- 1\leq N\leq 100
- 0\leq X_i\leq 100
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N
X_1 X_2 \ldots X_{5N}
Output
Print Takahashi's score.
Your answer will be considered correct if the absolute or relative error from the true value is at most 10^{-5}.
Sample Input 1
1 10 100 20 50 30
Sample Output 1
33.333333333333336
Since N=1, the grade given by one judge who gave the highest grade, and one with the lowest, are invalidated.
The 2-nd judge gave the highest grade (100 points), which is invalidated.
Additionally, the 1-st judge gave the lowest grade (10 points), which is also invalidated.
Thus, the average is \displaystyle\frac{20+50+30}{3}=33.333\cdots.
Note that the output will be considered correct if the absolute or relative error from the true value is at most 10^{-5}.
Sample Input 2
2 3 3 3 4 5 6 7 8 99 100
Sample Output 2
5.500000000000000
Since N=2, the grades given by the two judges who gave the highest grades, and two with the lowest, are invalidated.
The 10-th and 9-th judges gave the highest grades (100 and 99 points, respectively), which are invalidated.
Three judges, the 1-st, 2-nd, and 3-rd, gave the lowest grade (3 points), so two of them are invalidated.
Thus, the average is \displaystyle\frac{3+4+5+6+7+8}{6}=5.5.
Note that the choice of the two invalidated judges from the three with the lowest grades does not affect the answer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder社ではカードを使った 1 人ゲームが流行っています。
ゲームで使う各カードには、英小文字 1 文字または @ の文字が書かれており、いずれのカードも十分多く存在します。
ゲームは以下の手順で行います。
- カードを同じ枚数ずつ 2 列に並べる。
@のカードを、それぞれa,t,c,o,d,e,rのいずれかのカードと置き換える。- 2 つの列が一致していれば勝ち。そうでなければ負け。
このゲームに勝ちたいあなたは、次のようなイカサマをすることにしました。
- 手順 1 以降の好きなタイミングで、列内のカードを自由に並び替えてよい。
手順 1 で並べられた 2 つの列を表す 2 つの文字列 S,T が与えられるので、イカサマをしてもよいときゲームに勝てるか判定してください。
制約
- S,T は英小文字と
@からなる - S,T の長さは等しく 1 以上 2\times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
イカサマをしてもよいとき、ゲームに勝てるなら Yes、勝てないなら No と出力せよ。
入力例 1
ch@ku@ai choku@@i
出力例 1
Yes
@ をうまく置き換えることによって、両方とも chokudai と一致させることが可能です。
入力例 2
ch@kud@i akidu@ho
出力例 2
Yes
イカサマをし、@ をうまく置き換えることによって、両方とも chokudai と一致させることが可能です。
入力例 3
aoki @ok@
出力例 3
No
イカサマをしても勝つことはできません。
入力例 4
aa bb
出力例 4
No
Score : 300 points
Problem Statement
A single-player card game is popular in AtCoder Inc.
Each card in the game has a lowercase English letter or the symbol @ written on it. There is plenty number of cards for each kind.
The game goes as follows.
- Arrange the same number of cards in two rows.
- Replace each card with
@with one of the following cards:a,t,c,o,d,e,r. - If the two rows of cards coincide, you win. Otherwise, you lose.
To win this game, you will do the following cheat.
- Freely rearrange the cards within a row whenever you want after step 1.
You are given two strings S and T, representing the two rows you have after step 1. Determine whether it is possible to win with cheating allowed.
Constraints
- S and T consist of lowercase English letters and
@. - The lengths of S and T are equal and between 1 and 2\times 10^5, inclusive.
Input
The input is given from Standard Input in the following format:
S T
Output
If it is possible to win with cheating allowed, print Yes; otherwise, print No.
Sample Input 1
ch@ku@ai choku@@i
Sample Output 1
Yes
You can replace the @s so that both rows become chokudai.
Sample Input 2
ch@kud@i akidu@ho
Sample Output 2
Yes
You can cheat and replace the @s so that both rows become chokudai.
Sample Input 3
aoki @ok@
Sample Output 3
No
You cannot win even with cheating.
Sample Input 4
aa bb
Sample Output 4
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A = (A_1, A_2, \ldots, A_N) が与えられます。 K = 0, 1, 2, \ldots, N-1 のそれぞれについて、下記の問題を解いてください。
1 以上 N 以下の整数 i であって、次の条件を満たすものの個数を求めよ。
- A に含まれる整数のうち A_i より大きいものはちょうど K 種類である。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には K = i-1 の場合の問題の答えを出力せよ。
入力例 1
6 2 7 1 8 2 8
出力例 1
2 1 2 1 0 0
例として、K = 2 の場合の問題の答えを以下で求めます。
- A_1 = 2 に関して、A に含まれる整数のうち A_1 より大きいものは、7, 8 の 2 種類です。
- A_2 = 7 に関して、A に含まれる整数のうち A_2 より大きいものは、8 の 1 種類です。
- A_3 = 1 に関して、A に含まれる整数のうち A_3 より大きいものは、2, 7, 8 の 3 種類です。
- A_4 = 8 に関して、A に含まれる整数のうち A_4 より大きいものは、0 種類です(存在しません)。
- A_5 = 2 に関して、A に含まれる整数のうち A_5 より大きいものは、7, 8 の 2 種類です。
- A_6 = 8 に関して、A に含まれる整数のうち A_6 より大きいものは、0 種類です(存在しません)。
よって、A に含まれる整数のうちA_i より大きいものがちょうど K = 2 種類であるような i は、i = 1 と i = 5 の 2 つです。よって、K = 2 の場合の答えは 2 です。
入力例 2
1 1
出力例 2
1
入力例 3
10 979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527
出力例 3
2 1 2 1 2 1 1 0 0 0
Score : 300 points
Problem Statement
You are given a sequence A = (A_1, A_2, \ldots, A_N) of length N. For each K = 0, 1, 2, \ldots, N-1, solve the following problem.
Find the number of integers i between 1 and N (inclusive) such that:
- A contains exactly K distinct integers greater than A_i.
Constraints
- 1 \leq N \leq 2 \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 A_2 \ldots A_N
Output
Print N lines. For i = 1, 2, \ldots, N, the i-th line should contain the answer for K = i-1.
Sample Input 1
6 2 7 1 8 2 8
Sample Output 1
2 1 2 1 0 0
For example, we will find the answer for K=2.
- Regarding A_1 = 2, A contains 2 distinct integers greater than A_1: 7 and 8.
- Regarding A_2 = 7, A contains 1 distinct integer greater than A_2: 8.
- Regarding A_3 = 1, A contains 3 distinct integers greater than A_3: 2, 7, and 8.
- Regarding A_4 = 8, A contains 0 distinct integers greater than A_4 (there is no such integer).
- Regarding A_5 = 2, A contains 2 distinct integers greater than A_5: 7 and 8.
- Regarding A_6 = 8, A contains 0 distinct integers greater than A_6 (there is no such integer).
Thus, there are two i's, i = 1 and i = 5, such that A contains exactly K = 2 distinct integers greater than A_i. Therefore, the answer for K = 2 is 2.
Sample Input 2
1 1
Sample Output 2
1
Sample Input 3
10 979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527
Sample Output 3
2 1 2 1 2 1 1 0 0 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
英大文字および英小文字からなる長さ N の文字列 S が与えられます。
これから、文字列 S に対して Q 回の操作を行います。 i 番目 (1\leq i\leq Q) の操作は整数 2 つと文字 1 つからなる組 (t _ i,x _ i,c _ i) で表され、それぞれ次のような操作を表します。
- t _ i=1 のとき、S の x _ i 文字目を c _ i に変更する。
- t _ i=2 のとき、S に含まれる大文字すべてをそれぞれ小文字に変更する(x _ i,c _ i は操作に使用しない)。
- t _ i=3 のとき、S に含まれる小文字すべてをそれぞれ大文字に変更する(x _ i,c _ i は操作に使用しない)。
Q 回の操作がすべて終わったあとの S を出力してください。
制約
- 1\leq N\leq5\times10^5
- S は英大文字および英小文字からなる長さ N の文字列
- 1\leq Q\leq5\times10^5
- 1\leq t _ i\leq3\ (1\leq i\leq Q)
- t _ i=1 ならば 1\leq x _ i\leq N\ (1\leq i\leq Q)
- c _ i は英大文字もしくは英小文字
- t _ i\neq 1 ならば x _ i=0 かつ c _ i=
'a' - N,Q,t _ i,x _ i はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N S Q t _ 1 x _ 1 c _ 1 t _ 2 x _ 2 c _ 2 \vdots t _ Q x _ Q c _ Q
出力
答えを 1 行で出力せよ。
入力例 1
7 AtCoder 5 1 4 i 3 0 a 1 5 b 2 0 a 1 4 Y
出力例 1
atcYber
はじめ、文字列 S は AtCoder です。
- 1 番目の操作では、4 文字目を
iに変更します。変更後の S はAtCiderです。 - 2 番目の操作では、すべての小文字を大文字に変更します。変更後の S は
ATCIDERです。 - 3 番目の操作では、5 文字目を
bに変更します。変更後の S はATCIbERです。 - 4 番目の操作では、すべての大文字を小文字に変更します。変更後の S は
atciberです。 - 5 番目の操作では、4 文字目を
Yに変更します。変更後の S はatcYberです。
すべての操作が終わったあとの S は atcYber なので、atcYber と出力してください。
入力例 2
35 TheQuickBrownFoxJumpsOverTheLazyDog 10 2 0 a 1 19 G 1 13 m 1 2 E 1 21 F 2 0 a 1 27 b 3 0 a 3 0 a 1 15 i
出力例 2
TEEQUICKBROWMFiXJUGPFOVERTBELAZYDOG
Score : 400 points
Problem Statement
You are given a string S of length N consisting of uppercase and lowercase English letters.
Let us perform Q operations on the string S. The i-th operation (1\leq i\leq Q) is represented by a tuple (t _ i,x _ i,c _ i) of two integers and one character, as follows.
- If t _ i=1, change the x _ i-th character of S to c _ i.
- If t _ i=2, convert all uppercase letters in S to lowercase (do not use x _ i,c _ i for this operation).
- If t _ i=3, convert all lowercase letters in S to uppercase (do not use x _ i,c _ i for this operation).
Print the S after the Q operations.
Constraints
- 1\leq N\leq5\times10^5
- S is a string of length N consisting of uppercase and lowercase English letters.
- 1\leq Q\leq5\times10^5
- 1\leq t _ i\leq3\ (1\leq i\leq Q)
- If t _ i=1, then 1\leq x _ i\leq N\ (1\leq i\leq Q).
- c _ i is an uppercase or lowercase English letter.
- If t _ i\neq 1, then x _ i=0 and c _ i=
'a'. - N,Q,t _ i,x _ i are all integers.
Input
The input is given from Standard Input in the following format:
N S Q t _ 1 x _ 1 c _ 1 t _ 2 x _ 2 c _ 2 \vdots t _ Q x _ Q c _ Q
Output
Print the answer in a single line.
Sample Input 1
7 AtCoder 5 1 4 i 3 0 a 1 5 b 2 0 a 1 4 Y
Sample Output 1
atcYber
Initially, the string S is AtCoder.
- The first operation changes the 4-th character to
i, changing S toAtCider. - The second operation converts all lowercase letters to uppercase, changing S to
ATCIDER. - The third operation changes the 5-th character to
b, changing S toATCIbER. - The fourth operation converts all uppercase letters to lowercase, changing S to
atciber. - The fifth operation changes the 4-th character to
Y, changing S toatcYber.
After the operations, the string S is atcYber, so print atcYber.
Sample Input 2
35 TheQuickBrownFoxJumpsOverTheLazyDog 10 2 0 a 1 19 G 1 13 m 1 2 E 1 21 F 2 0 a 1 27 b 3 0 a 3 0 a 1 15 i
Sample Output 2
TEEQUICKBROWMFiXJUGPFOVERTBELAZYDOG