Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
長さ 6 の文字列 S が与えられます。S の先頭 3 文字は ABC であり、末尾 3 文字は数字であることが保証されます。
Sが、このコンテスト開始以前に AtCoder上で開催され終了したコンテストの略称であるかどうか判定してください。
ただし、文字列 T が「このコンテスト開始以前に AtCoder上で開催され終了したコンテストの略称」であるとは、以下の 348 個の文字列のうちいずれかに等しいことと定めます。
ABC001, ABC002, \ldots, ABC314, ABC315, ABC317, ABC318, \ldots, ABC348, ABC349
特に ABC316 が含まれないことに注意してください。
制約
- S は先頭 3 文字が
ABC、末尾 3 文字が数字である長さ 6 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
Sが、このコンテスト開始以前に AtCoder上で開催され終了したコンテストの略称であるなら Yes、そうでないなら No と出力せよ。
入力例 1
ABC349
出力例 1
Yes
ABC349 は先週AtCoder上で開催され終了したコンテストの略称です。
入力例 2
ABC350
出力例 2
No
ABC350 はこのコンテストです。まだ終了していません。
入力例 3
ABC316
出力例 3
No
ABC316 はAtCoder上で開催されていません。
Score: 100 points
Problem Statement
You are given a string S of length 6. It is guaranteed that the first three characters of S are ABC and the last three characters are digits.
Determine if S is the abbreviation of a contest held and concluded on AtCoder before the start of this contest.
Here, a string T is "the abbreviation of a contest held and concluded on AtCoder before the start of this contest" if and only if it equals one of the following 348 strings:
ABC001, ABC002, \ldots, ABC314, ABC315, ABC317, ABC318, \ldots, ABC348, ABC349.
Note that ABC316 is not included.
Constraints
- S is a string of length 6 where the first three characters are
ABCand the last three characters are digits.
Input
The input is given from Standard Input in the following format:
S
Output
If S is the abbreviation of a contest held and concluded on AtCoder before the start of this contest, print Yes; otherwise, print No.
Sample Input 1
ABC349
Sample Output 1
Yes
ABC349 is the abbreviation of a contest held and concluded on AtCoder last week.
Sample Input 2
ABC350
Sample Output 2
No
ABC350 is this contest, which has not concluded yet.
Sample Input 3
ABC316
Sample Output 3
No
ABC316 was not held on AtCoder.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
3 桁の正整数 N が与えられます。 N を十進法で表したとき、すべての桁の数字が同じであるかどうかを判定してください。
制約
- 100 \leq N \leq 999
- 入力される値は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N を十進法で表したとき、すべての桁の数字が同じであるならば Yes を、同じでないならば No を 1 行で出力せよ。
入力例 1
444
出力例 1
Yes
444 の各桁の数字は 4,4,4 で同じなので Yes を出力してください。
入力例 2
160
出力例 2
No
160 の各桁の数字は 1,6,0 で同じではないので、No を出力してください。
入力例 3
999
出力例 3
Yes
Score : 100 points
Problem Statement
You are given a 3-digit positive integer N. Determine whether all digits are the same when N is represented in decimal.
Constraints
- 100 \leq N \leq 999
- The input value is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
If all digits are the same when N is represented in decimal, output Yes in one line; otherwise, output No.
Sample Input 1
444
Sample Output 1
Yes
The digits of 444 are 4,4,4, which are the same, so output Yes.
Sample Input 2
160
Sample Output 2
No
The digits of 160 are 1,6,0, which are not the same, so output No.
Sample Input 3
999
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N \times N のグリッド S と M\times M のグリッド T が与えられます。上から i 行目、左から j 列目のマス目をマス (i,j) と表します。
S,T の各マスの色はそれぞれ N^2個の文字 S_{i,j} \; (1\leq i,j\leq N) および M^2 個の文字 T_{i,j} \; (1\leq i,j\leq M) によって表されます。
S_{i,j} が . のとき S のマス (i,j) は白色、S_{i,j} が # のとき S のマス (i,j) は黒色で塗られています。T についても同様です。
S の中から T を探してください。具体的には、以下の条件を満たす a,b \; (1 \leq a,b \leq N-M+1) を出力してください。
- すべての i,j \; (1\leq i,j \leq M) について、S_{a+i-1,b+j-1} = T_{i,j}
制約
- 1 \leq M \leq N \leq 50
- N,M は整数
- S_{i,j},T_{i,j} は
.または# - 条件を満たす a,b はちょうど 1 組存在する。
入力
入力は以下の形式で標準入力から与えられる。
N M
S_{1,1}S_{1,2}\dots S_{1,N}
S_{2,1}S_{2,2}\dots S_{2,N}
\vdots
S_{N,1}S_{N,2}\dots S_{N,N}
T_{1,1}T_{1,2}\dots T_{1,M}
T_{2,1}T_{2,2}\dots T_{2,M}
\vdots
T_{M,1}T_{M,2}\dots T_{M,M}
出力
a,b をこの順に空白区切りで 1 行に出力せよ。
入力例 1
3 2 #.# ..# ##. .# #.
出力例 1
2 2
S の 2 行目から 3 行目、2 列目から 3 列目の 2 \times 2 マスが T と一致します。
入力例 2
2 1 #. ## .
出力例 2
1 2
Score : 200 points
Problem Statement
You are given an N \times N grid S and an M \times M grid T. The cell at the i-th row from the top and the j-th column from the left is denoted by (i,j).
The colors of the cells in S and T are represented by N^2 characters S_{i,j} (1\leq i,j\leq N) and M^2 characters T_{i,j} (1\leq i,j\leq M), respectively. In grid S, cell (i,j) is white if S_{i,j} is ., and black if S_{i,j} is #. The same applies for grid T.
Find T within S. More precisely, output integers a and b (1 \leq a,b \leq N-M+1) that satisfy the following condition:
- S_{a+i-1,b+j-1} = T_{i,j} for every i,j (1\leq i,j \leq M).
Constraints
- 1 \leq M \leq N \leq 50
- N and M are integers.
- Each of S_{i,j} and T_{i,j} is
.or#. - There is exactly one pair (a,b) satisfying the condition.
Input
The input is given from Standard Input in the following format:
N M
S_{1,1}S_{1,2}\dots S_{1,N}
S_{2,1}S_{2,2}\dots S_{2,N}
\vdots
S_{N,1}S_{N,2}\dots S_{N,N}
T_{1,1}T_{1,2}\dots T_{1,M}
T_{2,1}T_{2,2}\dots T_{2,M}
\vdots
T_{M,1}T_{M,2}\dots T_{M,M}
Output
Print a and b in this order, separated by a space on one line.
Sample Input 1
3 2 #.# ..# ##. .# #.
Sample Output 1
2 2
The 2 \times 2 subgrid of S from the 2nd to the 3rd row and from the 2nd to the 3rd column matches T.
Sample Input 2
2 1 #. ## .
Sample Output 2
1 2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 人の人がいます。i \, (1 \leq i \leq N) 人目の人の姓は S_i、名は T_i です。
同姓同名であるような人の組が存在するか、すなわち 1 \leq i \lt j \leq N かつ S_i=S_j かつ T_i=T_j を満たすような整数対 (i,j) が存在するか判定してください。
制約
- 2 \leq N \leq 1000
- N は整数
- S_i,T_i は英小文字のみからなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N
S_1 T_1
S_2 T_2
\hspace{0.6cm}\vdots
S_N T_N
出力
同姓同名であるような人の組が存在するなら Yes を、存在しないなら No を出力せよ。
入力例 1
3 tanaka taro sato hanako tanaka taro
出力例 1
Yes
1 人目の人と 3 人目の人が同姓同名です。
入力例 2
3 saito ichiro saito jiro saito saburo
出力例 2
No
同姓同名であるような人の組は存在しません。
入力例 3
4 sypdgidop bkseq bajsqz hh ozjekw mcybmtt qfeysvw dbo
出力例 3
No
Score : 200 points
Problem Statement
There are N people. The family name and given name of the i-th person (1 \leq i \leq N) are S_i and T_i, respectively.
Determine whether there is a pair of people with the same family and given names. In other words, determine whether there is a pair of integers (i,j) such that 1 \leq i \lt j \leq N, S_i=S_j, and T_i=T_j.
Constraints
- 2 \leq N \leq 1000
- N is an integer.
- Each of S_i and T_i is a string of length between 1 and 10 (inclusive) consisting of English lowercase letters.
Input
Input is given from Standard Input in the following format:
N
S_1 T_1
S_2 T_2
\hspace{0.6cm}\vdots
S_N T_N
Output
If there is a pair of people with the same family and given names, print Yes; otherwise, print No.
Sample Input 1
3 tanaka taro sato hanako tanaka taro
Sample Output 1
Yes
The first and third persons have the same family and given names.
Sample Input 2
3 saito ichiro saito jiro saito saburo
Sample Output 2
No
No two persons have the same family and given names.
Sample Input 3
4 sypdgidop bkseq bajsqz hh ozjekw mcybmtt qfeysvw dbo
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 人の生徒からなるクラスがあり、i\,(1 \leq i \leq N) 番目の生徒の身長は A_i です。
j=1,2,\ldots,Q について、以下の質問に答えてください。
- N 人のうち、身長が x_j 以上の生徒は何人か?
制約
- 1 \leq N,Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq x_j \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q A_1 A_2 \ldots A_N x_1 x_2 \vdots x_Q
出力
Q 行出力せよ。
j\,(1 \leq j \leq Q) 行目には身長が x_j 以上の生徒の数を出力せよ。
入力例 1
3 1 100 160 130 120
出力例 1
2
身長が 120 以上の生徒は 2 番目の生徒と 3 番目の生徒です。
入力例 2
5 5 1 2 3 4 5 6 5 4 3 2
出力例 2
0 1 2 3 4
入力例 3
5 5 804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422
出力例 3
5 3 5 5 5
Score : 300 points
Problem Statement
There is a class with N students. The height of the i-th student (1 \leq i \leq N) is A_i.
For each j=1,2,\ldots,Q, answer the following question.
- How many of the N students have a height of at least x_j?
Constraints
- 1 \leq N,Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq x_j \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q A_1 A_2 \ldots A_N x_1 x_2 \vdots x_Q
Output
Print Q lines.
The j-th line (1 \leq j \leq Q) should contain the number of students with a height of at least x_j.
Sample Input 1
3 1 100 160 130 120
Sample Output 1
2
The students with a height of at least 120 are the 2-nd and 3-rd ones.
Sample Input 2
5 5 1 2 3 4 5 6 5 4 3 2
Sample Output 2
0 1 2 3 4
Sample Input 3
5 5 804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422
Sample Output 3
5 3 5 5 5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個の黒色のボールと M 個の白色のボールがあります。
ボールにはそれぞれ価値がつけられており、i\ (1\leq i\leq N) 個目の黒色のボールの価値は B_i、j\ (1\leq j\leq M) 個目の白色のボールの価値は W_j です。
黒色のボールの個数が白色のボールの個数以上になるようにボールを 0 個以上選ぶとき、選んだボールの価値の総和としてありうる最大値を求めてください。
制約
- 1\leq N,M\leq 2\times 10^5
- -10^9\leq B_i,W_j\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M B_1 B_2 \ldots B_N W_1 W_2 \ldots W_M
出力
答えを出力せよ。
入力例 1
4 3 8 5 -1 3 3 -2 -4
出力例 1
19
1,2,4 個目の黒色のボールと 1 個目の白色のボールを選ぶとき、選んだボールの価値の総和は 8+5+3+3=19 となりこれが最大です。
入力例 2
4 3 5 -10 -2 -5 8 1 4
出力例 2
15
1,3 個目の黒色のボールと 1,3 個目の白色のボールを選ぶとき、選んだボールの価値の総和は 5+(-2)+8+4=15 となりこれが最大です。
入力例 3
3 5 -36 -33 -31 12 12 28 24 27
出力例 3
0
ボールを 1 つも選ばないことも可能です。
Score : 300 points
Problem Statement
There are N black balls and M white balls.
Each ball has a value. The value of the i-th black ball (1 \le i \le N) is B_i, and the value of the j-th white ball (1 \le j \le M) is W_j.
Choose zero or more balls so that the number of black balls chosen is at least the number of white balls chosen. Among all such choices, find the maximum possible sum of the values of the chosen balls.
Constraints
- 1 \leq N,M \leq 2\times 10^5
- -10^9 \leq B_i, W_j \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M B_1 B_2 \ldots B_N W_1 W_2 \ldots W_M
Output
Print the answer.
Sample Input 1
4 3 8 5 -1 3 3 -2 -4
Sample Output 1
19
If you choose the 1st, 2nd, and 4th black balls, and the 1st white ball, the sum of their values is 8+5+3+3=19, which is the maximum.
Sample Input 2
4 3 5 -10 -2 -5 8 1 4
Sample Output 2
15
If you choose the 1st and 3rd black balls, and the 1st and 3rd white balls, the sum of their values is 5+(-2)+8+4=15, which is the maximum.
Sample Input 3
3 5 -36 -33 -31 12 12 28 24 27
Sample Output 3
0
It is possible to choose no balls.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
英小文字からなる文字列 S,T が与えられます。
S の空でない部分文字列 s のうち、T を(連続するとは限らない)部分列として含まないものの個数を求めてください。
ここで、S の 2 つの部分文字列は、取り出した箇所が異なれば文字列として等しくても区別するものとします。
部分文字列とは
文字列 X の部分文字列とは、X の先頭から 0 文字以上、末尾から 0 文字以上を削除して得られる文字列のことを指します。部分列とは
文字列 X の部分列とは,X の要素を 0 個以上選んで削除し,残った要素を元の順序を保って並べた文字列のことを指します.制約
- S は英小文字からなる文字列
- |S| を S の長さとして、1\le |S|\le2\times10 ^ 5
- T は英小文字からなる文字列
- |T| を T の長さとして、1\le |T|\le50
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
答えを出力せよ。
入力例 1
abrakadabra aba
出力例 1
51
例えば、S の 1 文字目から 3 文字目までからなる部分文字列 abr は T を部分列として含みません。
他にも、k(S の 5 文字目のみ)や akada(S の 4 文字目から 8 文字目)などの 51 個の部分文字列が条件を満たします。
文字列 abr は S の 1 文字目から 3 文字目までからなる部分文字列としても S の 8 文字目から 10 文字目までからなる部分文字列としても得ることができますが、文字列から取り出す箇所が異なるため区別して数えることに注意してください。
入力例 2
aaaaa a
出力例 2
0
S の空でない部分文字列は、すべて T を部分列として含みます。
よって、条件を満たす部分文字列は存在しないため、0 を出力してください。
入力例 3
rdddrdtdcdrrdcredctdordoeecrotet dcre
出力例 3
263
Score : 400 points
Problem Statement
You are given strings S and T consisting of lowercase English letters.
Among the non-empty substrings s of S, count those that do not contain T as a (not necessarily contiguous) subsequence.
Here, two substrings of S are distinguished if they are taken from different positions, even if they are equal as strings.
What is a substring?
A substring of a string X is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of X.What is a subsequence?
A subsequence of a string X is a string obtained by deleting zero or more elements from X and arranging the remaining elements in their original order.Constraints
- S is a string consisting of lowercase English letters.
- 1\le |S|\le2\times10 ^ 5, where |S| is the length of S.
- T is a string consisting of lowercase English letters.
- 1\le |T|\le50, where |T| is the length of T.
Input
The input is given from Standard Input in the following format:
S T
Output
Output the answer.
Sample Input 1
abrakadabra aba
Sample Output 1
51
For example, the substring abr consisting of the first through third characters of S does not contain T as a subsequence.
Including this, there are 51 substrings satisfying the condition, such as k (only the fifth character of S) and akada (the fourth through eighth characters of S).
Note that the string abr can be obtained both as the substring from the first to third characters of S and as the substring from the eighth to tenth characters of S, but they are taken from different positions, so they are counted separately.
Sample Input 2
aaaaa a
Sample Output 2
0
All non-empty substrings of S contain T as a subsequence.
Thus, there are no substrings satisfying the condition, so output 0.
Sample Input 3
rdddrdtdcdrrdcredctdordoeecrotet dcre
Sample Output 3
263
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
(1,2,\ldots,N) の並べ替え P=(P _ 1,P _ 2,\ldots,P _ N) が与えられます。
次の操作を K 回行います。
- i=1,2,\ldots,N に対して同時に P _ i を P _ {P _ i} で更新する
すべての操作を終えたあとの P を出力してください。
制約
- 1\leq N\leq2\times10 ^ 5
- 1\leq K\leq10 ^ {18}
- 1\leq P _ i\leq N\ (1\leq i\leq N)
- P _ i\neq P _ j\ (1\leq i\lt j\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K P _ 1 P _ 2 \ldots P _ N
出力
操作をすべて行ったあとの P について、P _ 1,P _ 2,\ldots,P _ N をこの順に空白を区切りとして出力せよ。
入力例 1
6 3 5 6 3 1 2 4
出力例 1
6 1 3 2 4 5
それぞれの操作によって、P は次のように変化します。
- 1 回目の操作の結果、P=(2,4,3,5,6,1) となります。
- 2 回目の操作の結果、P=(4,5,3,6,1,2) となります。
- 3 回目の操作の結果、P=(6,1,3,2,4,5) となります。
よって、6 1 3 2 4 5 を出力してください。
入力例 2
5 1000000000000000000 1 2 3 4 5
出力例 2
1 2 3 4 5
P _ i=i なので、何度操作を行っても P は変化しません。
入力例 3
29 51912426 7 24 8 23 6 1 4 19 11 18 20 9 17 28 22 27 15 2 12 26 10 13 14 25 5 29 3 21 16
出力例 3
18 23 16 24 21 10 2 27 19 7 12 8 13 5 15 26 17 4 3 9 1 22 25 14 28 11 29 6 20
Score : 475 points
Problem Statement
You are given a permutation P=(P_1,P_2,\ldots,P_N) of (1,2,\ldots,N).
The following operation will be performed K times:
- For i=1,2,\ldots,N, simultaneously update P_i to P_{P_i}.
Print P after all operations.
Constraints
- 1\leq N\leq2\times10^5
- 1\leq K\leq10^{18}
- 1\leq P_i\leq N\ (1\leq i\leq N)
- P_i\neq P_j\ (1\leq i\lt j\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K P_1 P_2 \ldots P_N
Output
For the P after all operations, print P_1,P_2,\ldots,P_N in this order, separated by spaces.
Sample Input 1
6 3 5 6 3 1 2 4
Sample Output 1
6 1 3 2 4 5
With each operation, P changes as follows:
- After the first operation, P is (2,4,3,5,6,1).
- After the second operation, P is (4,5,3,6,1,2).
- After the third operation, P is (6,1,3,2,4,5).
Thus, print 6 1 3 2 4 5.
Sample Input 2
5 1000000000000000000 1 2 3 4 5
Sample Output 2
1 2 3 4 5
Since P_i=i, P does not change no matter how many operations are performed.
Sample Input 3
29 51912426 7 24 8 23 6 1 4 19 11 18 20 9 17 28 22 27 15 2 12 26 10 13 14 25 5 29 3 21 16
Sample Output 3
18 23 16 24 21 10 2 27 19 7 12 8 13 5 15 26 17 4 3 9 1 22 25 14 28 11 29 6 20
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
縦の長さが A、横の長さが B の長方形の内部に描ける正三角形の一辺の長さの最大値を求めてください。
制約
- 1 \leq A,B \leq 1000
- A,B は整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-9} 以下であれば正解として扱われる。
入力例 1
1 1
出力例 1
1.03527618041008295791
下図のように描くのが最適で、一辺の長さが \sqrt{6} - \sqrt{2} になります。

なお、この出力例の値は \sqrt{6}- \sqrt{2} と厳密には一致しませんが、誤差が 10^{-9} 以下なので正解として扱われます。
Score : 500 points
Problem Statement
Find the maximum side length of a regular triangle that can be drawn within a rectangle whose side lengths are A and B.
Constraints
- 1 \leq A,B \leq 1000
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer.
Your output is considered correct if the absolute or relative error from the true answer is at most 10^{-9}.
Sample Input 1
1 1
Sample Output 1
1.03527618041008295791
The following figure shows an optimal drawing, with the side length of \sqrt{6} - \sqrt{2}.

Note that the sample output does not strictly match \sqrt{6}- \sqrt{2}, but the error is within 10^{-9}, so it is considered correct.