実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。
S の中で a
と b
が隣接する箇所があれば Yes
を、なければ No
を出力してください。(a
と b
の順序は問いません。)
制約
- 2 \leq N \leq 100
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の中で a
と b
が隣接する箇所があれば Yes
を、なければ No
を出力せよ。
入力例 1
3 abc
出力例 1
Yes
文字列 abc
は 1 文字目にある a
と 2 文字目にある b
が隣接しています。よって Yes
を出力してください。
入力例 2
2 ba
出力例 2
Yes
文字列 ba
は 2 文字目にある a
と 1 文字目にある b
が隣接しています。(a
と b
の順番は逆でも良い点に注意してください。)
入力例 3
7 atcoder
出力例 3
No
Score : 100 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters.
If there are any adjacent occurrences of a
and b
in S, print Yes
; otherwise, print No
. (The order of a
and b
does not matter.)
Constraints
- 2 \leq N \leq 100
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
If there are any adjacent occurrences of a
and b
in S, print Yes
; otherwise, print No
.
Sample Input 1
3 abc
Sample Output 1
Yes
The string abc
has a
as the first character and b
as the second character, which are adjacent. Thus, print Yes
.
Sample Input 2
2 ba
Sample Output 2
Yes
The string ba
has a
as the second character and b
as the first character, which are adjacent. (Note that the order of a
and b
does not matter.)
Sample Input 3
7 atcoder
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
整数 B が与えられます。
A^A = B であるような正の整数 A が存在するならばその値を、存在しないならば -1
を出力してください。
制約
- 1 \leq B \leq 10^{18}
- B は整数
入力
入力は以下の形式で標準入力から与えられる。
B
出力
A^A = B であるような正の整数 A が存在するならばその値を、存在しないならば -1
を出力せよ。
A^A = B を満たす正の整数 A が複数ある場合は、どれを出力しても正解とみなされる。
入力例 1
27
出力例 1
3
3^3 = 27 なので 3 を出力します。
入力例 2
100
出力例 2
-1
A^A = B を満たす A は存在しません。
入力例 3
10000000000
出力例 3
10
Score : 200 points
Problem Statement
You are given an integer B.
If there exists a positive integer A such that A^A = B, print its value; otherwise, output -1
.
Constraints
- 1 \leq B \leq 10^{18}
- B is an integer.
Input
The input is given from Standard Input in the following format:
B
Output
If there exists a positive integer A such that A^A = B, print its value; otherwise, print -1
.
If there are multiple positive integers A such that A^A = B, any of them will be accepted.
Sample Input 1
27
Sample Output 1
3
3^3 = 27, so print 3.
Sample Input 2
100
Sample Output 2
-1
There is no A such that A^A = B.
Sample Input 3
10000000000
Sample Output 3
10
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
9\times 9 のマス目 A があり、各マスには 1 以上 9 以下の整数が書き込まれています。
具体的には、 A の上から i 行目、左から j 列目のマスには A_{i,j} が書き込まれています。
A が次の条件をすべてみたしているならば Yes
を、そうでないならば No
を出力してください。
- A の各行について、その行に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
- A の各列について、その列に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
- A の行を上から 3 行ずつ 3 つに分け、同様に列も左から 3 列ずつ 3 つに分ける。 これによって A を 9 つの 3\times 3 のマス目に分けたとき、それぞれの 3\times 3 のマス目には 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
制約
- 1\leq A_{i,j}\leq 9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A_{1,1} A_{1,2} \ldots A_{1,9} A_{2,1} A_{2,2} \ldots A_{2,9} \vdots A_{9,1} A_{9,2} \ldots A_{9,9}
出力
マス目 A が問題文の条件をすべてみたすならば Yes
を、
そうでないならば No
を出力せよ。
入力例 1
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 4 5 6 7 8 9 1 5 6 7 8 9 1 2 3 4 8 9 1 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 6 7 8 9 1 2 3 4 5 9 1 2 3 4 5 6 7 8
出力例 1
Yes
マス目 A は次のようになっています。
マス目 A は 3 つの条件をすべてみたしているため、Yes
を出力します。
入力例 2
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 1 3 4 5 6 7 8 9 1 2 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 4 5 7 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 7 9 1 2 3 4 5 6 7 8
出力例 2
No
マス目 A は次のようになっています。
例えば左上の 3\times 3 のマス目に注目すると 3 つめの条件をみたしていないことが分かるため、No
を出力します。
入力例 3
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6
出力例 3
No
マス目 A は次のようになっています。
例えば一番左の列に注目すると 2 つめの条件をみたしていないことが分かるため、No
を出力します。
Score : 250 points
Problem Statement
There is a 9\times 9 grid A, where each cell contains an integer between 1 and 9, inclusive.
Specifically, the cell at the i-th row from the top and j-th column from the left contains A_{i,j}.
If A satisfies all of the following conditions, print Yes
. Otherwise, print No
.
- For each row of A, the nine cells in that row contain each integer from 1 to 9 exactly once.
- For each column of A, the nine cells in that column contain each integer from 1 to 9 exactly once.
- Divide the rows of A into three groups, each of three rows, from top to bottom, and similarly divide the columns into three groups, each of three columns, from left to right. Each 3\times 3 grid obtained from A in this way contains each integer from 1 to 9 exactly once.
Constraints
- 1\leq A_{i,j}\leq 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A_{1,1} A_{1,2} \ldots A_{1,9} A_{2,1} A_{2,2} \ldots A_{2,9} \vdots A_{9,1} A_{9,2} \ldots A_{9,9}
Output
If the grid A satisfies all the conditions in the problem statement, print Yes
; otherwise, print No
.
Sample Input 1
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 4 5 6 7 8 9 1 5 6 7 8 9 1 2 3 4 8 9 1 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 6 7 8 9 1 2 3 4 5 9 1 2 3 4 5 6 7 8
Sample Output 1
Yes
The grid A is shown below.
The grid A satisfies all three conditions, so print Yes
.
Sample Input 2
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 1 3 4 5 6 7 8 9 1 2 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 4 5 7 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 7 9 1 2 3 4 5 6 7 8
Sample Output 2
No
The grid A is shown below.
For example, if you look at the top left 3\times 3 grid, you can see that the third condition is unsatisfied, so print No
.
Sample Input 3
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6
Sample Output 3
No
The grid A is shown below.
For example, if you look at the leftmost column, you can see that the second condition is unsatisfied, so print No
.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N 以下の正整数からなる長さ M の数列の組 (S, T) = ((S_1, S_2, \dots, S_M), (T_1, T_2, \dots, T_M)) が 良い数列の組である とは、(S, T) が次の条件を満たすことを言います。
- 0,1 からなる長さ N の数列 X = (X_1, X_2, \dots, X_N) であって次の条件を満たすものが存在する。
- i=1, 2, \dots, M それぞれについて、X_{S_i} \neq X_{T_i} が成立する。
N 以下の正整数からなる長さ M の数列の組 (A, B) = ((A_1, A_2, \dots, A_M), (B_1, B_2, \dots, B_M)) が与えられます。(A, B) が良い数列の組である場合は Yes
を、そうでない場合は No
を出力してください。
制約
- 1 \leq N, M \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_M B_1 B_2 \dots B_M
出力
(A, B) が良い数列の組である場合は Yes
を、そうでない場合は No
を出力せよ。
入力例 1
3 2 1 2 2 3
出力例 1
Yes
X=(0,1,0) とすると、X は 0,1 からなる長さ N の数列で、 X_{A_1} \neq X_{B_1} かつ X_{A_2} \neq X_{B_2} を満たします。
よって、(A,B) は良い数列の組としての条件を満たしています。
入力例 2
3 3 1 2 3 2 3 1
出力例 2
No
条件を満たすような数列 X は存在しないので、(A, B) は良い数列の組ではありません。
入力例 3
10 1 1 1
出力例 3
No
入力例 4
7 8 1 6 2 7 5 4 2 2 3 2 7 2 1 2 3 3
出力例 4
Yes
Score : 400 points
Problem Statement
A pair of sequences of length M consisting of positive integers at most N, (S, T) = ((S_1, S_2, \dots, S_M), (T_1, T_2, \dots, T_M)), is said to be a good pair of sequences when (S, T) satisfies the following condition.
- There exists a sequence X = (X_1, X_2, \dots, X_N) of length N consisting of 0 and 1 that satisfies the following condition:
- X_{S_i} \neq X_{T_i} for each i=1, 2, \dots, M.
You are given a pair of sequences of length M consisting of positive integers at most N: (A, B) = ((A_1, A_2, \dots, A_M), (B_1, B_2, \dots, B_M)). If (A, B) is a good pair of sequences, print Yes
; otherwise, print No
.
Constraints
- 1 \leq N, M \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_M B_1 B_2 \dots B_M
Output
If (A, B) is a good pair of sequences, print Yes
; otherwise, print No
.
Sample Input 1
3 2 1 2 2 3
Sample Output 1
Yes
If we set X=(0,1,0), then X is a sequence of length N consisting of 0 and 1 that satisfies X_{A_1} \neq X_{B_1} and X_{A_2} \neq X_{B_2}.
Thus, (A, B) satisfies the condition of being a good pair of sequences.
Sample Input 2
3 3 1 2 3 2 3 1
Sample Output 2
No
No sequence X satisfies the condition, so (A, B) is not a good pair of sequences.
Sample Input 3
10 1 1 1
Sample Output 3
No
Sample Input 4
7 8 1 6 2 7 5 4 2 2 3 2 7 2 1 2 3 3
Sample Output 4
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
高橋君は N 回コンテストに参加し、i 回目に参加したコンテストにおいてパフォーマンス P_i を獲得しました。
高橋君はこの中から (1 つ以上) いくつかのコンテストを選び、それらの結果から計算される高橋君のレートを最大にしたいと考えています。
コンテストをうまく選んだとき、高橋君のレートとしてあり得る最大の値を求めてください。
ただし、高橋君のレート R は、高橋君の選んだコンテストの数が k 個であり、 選んだコンテストにおけるパフォーマンスが 参加した順に それぞれ (Q_1,Q_2,\ldots,Q_k) であるとき、
によって計算されます。
制約
- 1\leq N\leq 5000
- 1\leq P_i\leq 5000
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N P_1 P_2 \ldots P_N
出力
高橋君のレートとしてあり得る最大の値を出力せよ。
出力は、真の値との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。
入力例 1
3 1000 600 1200
出力例 1
256.735020470879931
高橋君が 1 回目と 3 回目のコンテストを選んだ時、レートは、
\displaystyle R=\frac{0.9\times 1000+ 1.0\times 1200}{0.9+1.0}-\frac{1200}{\sqrt{2}}=256.73502...
となり、この時レートが最大となります。
入力例 2
3 600 1000 1200
出力例 2
261.423219407873376
1,2,3 回目のコンテストすべてを選んだとき、レートが最大となります。
入力例 3
1 100
出力例 3
-1100.000000000000000
レートは負になることもあります。
Score : 475 points
Problem Statement
Takahashi participated in N contests and earned a performance P_i in the i-th contest.
He wants to choose some (at least one) contests from these and maximize his rating calculated from the results of those contests.
Find the maximum possible rating he can achieve by optimally choosing the contests.
Here, Takahashi's rating R is calculated as the following, where k is the number of chosen contests and (Q_1, Q_2, \ldots, Q_k) are the performances in the chosen contests in the order he participated:
Constraints
- 1\leq N\leq 5000
- 1\leq P_i\leq 5000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N P_1 P_2 \ldots P_N
Output
Print the maximum possible rating that Takahashi can achieve.
Your output will be considered correct if the absolute or relative error from the true value is at most 10^{-6}.
Sample Input 1
3 1000 600 1200
Sample Output 1
256.735020470879931
If Takahashi chooses the first and third contests, his rating will be:
\displaystyle R=\frac{0.9\times 1000+ 1.0\times 1200}{0.9+1.0}-\frac{1200}{\sqrt{2}}=256.73502....
This is the maximum possible rating.
Sample Input 2
3 600 1000 1200
Sample Output 2
261.423219407873376
The rating is maximized when all the first, second, and third contests are selected.
Sample Input 3
1 100
Sample Output 3
-1100.000000000000000
The rating can also be negative.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 550 点
問題文
数直線上にりんごの木が並んでおり、 N 個のりんごが木から落ちてきます。
具体的には 1\leq i\leq N について、時刻 T_i に座標 X_i にりんごが落ちてきます。
高橋君は耐久性が D , 長さ W のカゴを持っており、一度だけ 次の行動を取ることができます。
正整数 S, L を選ぶ。高橋君は時刻 S-0.5 に L-0.5\leq x\leq L+W-0.5 の範囲を覆うようにカゴを設置し、時刻 S+D-0.5 に回収する。 高橋君はカゴを設置してから回収するまでの間に、カゴが設置されていた範囲に落ちてきたりんごをすべて得ることができる。
高橋君は一度設置したカゴを動かしたり、回収したカゴを再度設置することはできません。
高橋君が得られるりんごの数の最大値を求めてください。
制約
- 1 \leq N\leq 2\times 10^5
- 1 \leq D\leq 2\times 10^5
- 1 \leq W\leq 2\times 10^5
- 1 \leq T_i\leq 2\times 10^5
- 1 \leq X_i\leq 2\times 10^5
- (T_i,X_i) はすべて異なる。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D W T_1 X_1 T_2 X_2 \vdots T_N X_N
出力
高橋君が得られるりんごの数の最大値を出力せよ。
入力例 1
8 4 3 1 1 3 4 6 4 5 2 4 2 4 3 5 5 7 3
出力例 1
5
高橋君は S=3, L=2 を選ぶと、時刻 2.5 から 6.5 までカゴを 1.5\leq x\leq 4.5 の範囲に設置します。このとき、
- 時刻 T_2=3 に 座標 X_2=4 に落ちてくるりんご
- 時刻 T_3=6 に 座標 X_3=4 に落ちてくるりんご
- 時刻 T_4=5 に 座標 X_4=2 に落ちてくるりんご
- 時刻 T_5=4 に 座標 X_5=2 に落ちてくるりんご
- 時刻 T_6=4 に 座標 X_6=3 に落ちてくるりんご
の 5 個のりんごを得ることができます。
どのように行動しても 6 個以上のりんごを得ることはできないため、5 を出力します。
Score : 550 points
Problem Statement
There are apple trees lined up on a number line, and N apples fall from the trees.
Specifically, for each 1\leq i\leq N, an apple falls at coordinate X_i at time T_i.
Takahashi has a basket with durability D and length W, and he can take the following action exactly once.
Choose positive integers S and L. He sets up the basket to cover the range L-0.5\leq x\leq L+W-0.5 at time S-0.5, and retrieves it at time S+D-0.5. He gets all the apples that fell into the range covered by the basket between the time it was set up and the time it was retrieved.
He cannot move the basket once it has been set up, nor can he set it up again once it has been retrieved.
Find the maximum number of apples that he can get.
Constraints
- 1 \leq N\leq 2\times 10^5
- 1 \leq D\leq 2\times 10^5
- 1 \leq W\leq 2\times 10^5
- 1 \leq T_i\leq 2\times 10^5
- 1 \leq X_i\leq 2\times 10^5
- All pairs (T_i,X_i) are different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N D W T_1 X_1 T_2 X_2 \vdots T_N X_N
Output
Print the maximum number of apples that Takahashi can get.
Sample Input 1
8 4 3 1 1 3 4 6 4 5 2 4 2 4 3 5 5 7 3
Sample Output 1
5
If Takahashi chooses S=3 and L=2, he will set up the basket to cover the range 1.5\leq x\leq 4.5 from time 2.5 to 6.5. Then, he gets the following five apples:
- The apple that falls at coordinate X_2=4 at time T_2=3
- The apple that falls at coordinate X_3=4 at time T_3=6
- The apple that falls at coordinate X_4=2 at time T_4=5
- The apple that falls at coordinate X_5=2 at time T_5=4
- The apple that falls at coordinate X_6=3 at time T_6=4
There is no way to get six or more apples, so print 5.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 650 点
問題文
この問題における良い数列の組の定義は D 問題と同じです。
N 以下の正整数からなる長さ M の数列の組 (S, T) = ((S_1, S_2, \dots, S_M), (T_1, T_2, \dots, T_M)) が 良い数列の組である とは、(S, T) が次の条件を満たすことを言います。
- 0,1 からなる長さ N の数列 X = (X_1, X_2, \dots, X_N) であって次の条件を満たすものが存在する。
- i=1, 2, \dots, M それぞれについて、X_{S_i} \neq X_{T_i} が成立する。
N 以下の正整数からなる長さ M の数列の組 (A, B) = ((A_1, A_2, \dots, A_M), (B_1, B_2, \dots, B_M)) としてあり得るものは N^{2M} 通りありますが、そのような数列の組のうち良い数列の組であるものの個数を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 30
- 1 \leq M \leq 10^9
- N, M は整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
N 以下の正整数からなる長さ M の数列の組のうち、良い数列の組であるものの個数を 998244353 で割った余りを出力せよ。
入力例 1
3 2
出力例 1
36
例えば A=(1,2), B=(2,3) のとき (A, B) は良い数列の組です。X=(0,1,0) とすると、X は 0,1 からなる長さ N の数列で、 X_{A_1} \neq X_{B_1} かつ X_{A_2} \neq X_{B_2} を満たします。よって、(A,B) は良い数列の組としての条件を満たしています。
良い数列の組は全部で 36 個あるので、これを出力します。
入力例 2
3 3
出力例 2
168
入力例 3
12 34
出力例 3
539029838
入力例 4
20 231104
出力例 4
966200489
Score : 650 points
Problem Statement
The definition of a good pair of sequences in this problem is the same as in Problem D.
A pair of sequences of length M consisting of positive integers at most N, (S, T) = ((S_1, S_2, \dots, S_M), (T_1, T_2, \dots, T_M)), is said to be a good pair of sequences when (S, T) satisfies the following condition.
- There exists a sequence X = (X_1, X_2, \dots, X_N) of length N consisting of 0 and 1 that satisfies the following condition:
- X_{S_i} \neq X_{T_i} for each i=1, 2, \dots, M.
Among the N^{2M} possible pairs of sequences of length M consisting of positive integers at most N, (A, B) = ((A_1, A_2, \dots, A_M), (B_1, B_2, \dots, B_M)), find the number, modulo 998244353, of those that are good pairs of sequences.
Constraints
- 1 \leq N \leq 30
- 1 \leq M \leq 10^9
- N and M are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number, modulo 998244353, of pairs of sequences of length M consisting of positive integers at most N that are good pairs of sequences.
Sample Input 1
3 2
Sample Output 1
36
For example, if A=(1,2), B=(2,3), then (A, B) is a good pair of sequences. Indeed, if we set X=(0,1,0), then X is a sequence of length N consisting of 0 and 1 that satisfies X_{A_1} \neq X_{B_1} and X_{A_2} \neq X_{B_2}. Thus, (A, B) satisfies the condition of being a good pair of sequences.
There are a total of 36 good pairs of sequences, so print this number.
Sample Input 2
3 3
Sample Output 2
168
Sample Input 3
12 34
Sample Output 3
539029838
Sample Input 4
20 231104
Sample Output 4
966200489