Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
AtCoder 王国の住民は A 時になるとたこ焼きへの愛を叫ぶことになっています。
AtCoder 王国に住む高橋君は毎日 B 時に就寝し C 時に起床します。高橋君は、起きているときはたこ焼きへの愛を叫ぶことができ、寝ているときは叫ぶことができません。高橋君が毎日たこ焼きへの愛を叫ぶことができているか判定してください。ただし、一日は 24 時間であり、高橋君が寝ている時間は 24 時間未満であるとします。
制約
- 0\leq A,B,C\lt 24
- A,B,C は相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
高橋君が毎日たこ焼きへの愛を叫ぶことができているならば Yes を、そうでないならば No を出力せよ。
入力例 1
21 8 14
出力例 1
Yes
高橋君は毎日 8 時に就寝し 14 時に起床します。21 時には起きているため、高橋君は毎日たこ焼きへの愛を叫ぶことができます。よって Yes を出力します。
入力例 2
0 21 7
出力例 2
No
高橋君は毎日 21 時に就寝し 7 時に起床します。0 時には起きていないため、高橋君は毎日たこ焼きへの愛を叫ぶことができません。よって No を出力します。
入力例 3
10 7 17
出力例 3
No
Score : 150 points
Problem Statement
In the Kingdom of AtCoder, residents are required to shout their love for takoyaki at A o'clock every day.
Takahashi, who lives in the Kingdom of AtCoder, goes to bed at B o'clock and wakes up at C o'clock every day (in the 24-hour clock). He can shout his love for takoyaki when he is awake, but cannot when he is asleep. Determine whether he can shout his love for takoyaki every day. Here, a day has 24 hours, and his sleeping time is less than 24 hours.
Constraints
- 0\leq A,B,C\lt 24
- A, B, and C are pairwise different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B C
Output
Print Yes if Takahashi can shout his love for takoyaki every day, and No otherwise.
Sample Input 1
21 8 14
Sample Output 1
Yes
Takahashi goes to bed at 8 o'clock and wakes up at 14 o'clock every day. He is awake at 21 o'clock, so he can shout his love for takoyaki every day. Therefore, print Yes.
Sample Input 2
0 21 7
Sample Output 2
No
Takahashi goes to bed at 21 o'clock and wakes up at 7 o'clock every day. He is not awake at 0 o'clock, so he cannot shout his love for takoyaki every day. Therefore, print No.
Sample Input 3
10 7 17
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
N 個の整数 A _ 1,A _ 2,\ldots,A _ N が与えられます。
これらの値がすべて等しいならば Yes 、そうでなければ No と出力してください。
制約
- 2\leq N\leq100
- 1\leq A _ i\leq100\ (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \ldots A _ N
出力
与えられた A _ 1,A _ 2,\ldots,A _ N の値がすべて等しいなら Yes を、そうでなければ No を 1 行で出力せよ。
入力例 1
3 3 2 4
出力例 1
No
A _ 1\neq A _ 2 なので、No と出力してください。
入力例 2
4 3 3 3 3
出力例 2
Yes
A _ 1=A _ 2=A _ 3=A _ 4 なので、Yes と出力してください。
入力例 3
10 73 8 55 26 97 48 37 47 35 55
出力例 3
No
Score : 100 points
Problem Statement
You are given N integers A _ 1,A _ 2,\ldots,A _ N.
If their values are all equal, print Yes; otherwise, print No.
Constraints
- 2\leq N\leq100
- 1\leq A _ i\leq100\ (1\leq i\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A _ 1 A _ 2 \ldots A _ N
Output
Print a single line containing Yes if the values of the given A _ 1,A _ 2,\ldots,A _ N are all equal, and No otherwise.
Sample Input 1
3 3 2 4
Sample Output 1
No
We have A _ 1\neq A _ 2, so you should print No.
Sample Input 2
4 3 3 3 3
Sample Output 2
Yes
We have A _ 1=A _ 2=A _ 3=A _ 4, so you should print Yes.
Sample Input 3
10 73 8 55 26 97 48 37 47 35 55
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 個の台が一列に並んでおり、左から i 番目の台の高さは H_i です。
高橋君は最初、左端の台の上に立っています。
高橋君は高い所が好きなので、次のルールで可能な限り移動を繰り返します。
- いま立っているのが右端の台ではなく、かつ、右隣にある台の高さが自分がいま立っている台より高いとき、右隣の台に移動する
最終的に高橋君が立っている台の高さを求めてください。
制約
- 2 \leq N \leq 10^5
- 1 \leq H_i \leq 10^9
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N H_1 \ldots H_N
出力
答えを出力せよ。
入力例 1
5 1 5 10 4 2
出力例 1
10
最初、高橋君は左端にある高さ 1 の台に立っています。右隣の台の高さは 5 であり、いま立っている台より高いので、右隣の台に移動します。
移動後、高橋君は左から 2 番目にある高さ 5 の台に立っています。右隣の台の高さは 10 であり、いま立っている台より高いので、右隣の台に移動します。
移動後、高橋君は左から 3 番目にある高さ 10 の台に立っています。右隣の台の高さは 4 であり、いま立っている台より低いので、高橋君は移動をやめます。
よって、最終的に高橋君が立っている台の高さは 10 です。
入力例 2
3 100 1000 100000
出力例 2
100000
入力例 3
4 27 1828 1828 9242
出力例 3
1828
Score : 200 points
Problem Statement
There are N platforms arranged in a row. The height of the i-th platform from the left is H_i.
Takahashi is initially standing on the leftmost platform.
Since he likes heights, he will repeat the following move as long as possible.
- If the platform he is standing on is not the rightmost one, and the next platform to the right has a height greater than that of the current platform, step onto the next platform.
Find the height of the final platform he will stand on.
Constraints
- 2 \leq N \leq 10^5
- 1 \leq H_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N H_1 \ldots H_N
Output
Print the answer.
Sample Input 1
5 1 5 10 4 2
Sample Output 1
10
Takahashi is initially standing on the leftmost platform, whose height is 1. The next platform to the right has a height of 5 and is higher than the current platform, so he steps onto it.
He is now standing on the 2-nd platform from the left, whose height is 5. The next platform to the right has a height of 10 and is higher than the current platform, so he steps onto it.
He is now standing on the 3-rd platform from the left, whose height is 10. The next platform to the right has a height of 4 and is lower than the current platform, so he stops moving.
Thus, the height of the final platform Takahashi will stand on is 10.
Sample Input 2
3 100 1000 100000
Sample Output 2
100000
Sample Input 3
4 27 1828 1828 9242
Sample Output 3
1828
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
文字列 S が与えられます。
S の連続する部分文字列のうち、回文であるものの長さの最大値を求めてください。
ただし、S の連続する部分文字列であって回文であるものは常に存在します。
制約
- S は長さ 2 以上 100 以下の英大文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
TOYOTA
出力例 1
5
TOYOTA の連続する部分文字列 TOYOT は長さ 5 の回文です。
TOYOTA の唯一の長さ 6 の連続する部分文字列 TOYOTA は回文でないので、5 を出力します。
入力例 2
ABCDEFG
出力例 2
1
すべての長さ 1 の連続する部分文字列は回文です。
入力例 3
AAAAAAAAAA
出力例 3
10
Score : 200 points
Problem Statement
You are given a string S.
Find the maximum length of a contiguous substring of S that is a palindrome.
Note that there is always a contiguous substring of S that is a palindrome.
Constraints
- S is a string of length between 2 and 100, inclusive, consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
TOYOTA
Sample Output 1
5
TOYOT, a contiguous substring of TOYOTA, is a palindrome of length 5.
TOYOTA, the only length-6 contiguous substring of TOYOTA, is not a palindrome, so print 5.
Sample Input 2
ABCDEFG
Sample Output 2
1
Every contiguous substring of length 1 is a palindrome.
Sample Input 3
AAAAAAAAAA
Sample Output 3
10
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の正数列 A=(A_1,A_2,\dots,A_N) が与えられます。以下で定義される長さ N の数列 B = (B_1,B_2,\dots,B_N) を求めてください。
- i=1,2,\dots,N について、B_i を次のように定義する:
- A_i と等しい要素が i の直前に出現した位置を B_i とする。そのような位置が存在しなければ B_i=-1 とする。
より正確には、正整数 j であって,A_i = A_j となる j < i が存在するならば、そのうち最大の j を B_i とする。そのような j が存在しなければ B_i=-1 とする。
- A_i と等しい要素が i の直前に出現した位置を B_i とする。そのような位置が存在しなければ B_i=-1 とする。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
B の要素を空白区切りで1行に出力せよ。
入力例 1
5 1 2 1 1 3
出力例 1
-1 -1 1 3 -1
- i=1: A_1=1 より前に 1 は現れないので、B_1=-1 です。
- i=2: A_2=2 より前に 2 は現れないので、B_2=-1 です。
- i=3: A_3=1 の直前に現れた 1 は A_1 なので、B_3=1 です。
- i=4: A_4=1 の直前に現れた 1 は A_3 なので、B_4=3 です。
- i=5: A_5=3 より前に 3 は現れないので、B_5=-1 です。
入力例 2
4 1 1000000000 1000000000 1
出力例 2
-1 -1 2 1
Score : 300 points
Problem Statement
You are given a sequence of N positive numbers, A = (A_1, A_2, \dots, A_N). Find the sequence B = (B_1, B_2, \dots, B_N) of length N defined as follows.
- For i = 1, 2, \dots, N, define B_i as follows:
- Let B_i be the most recent position before i where an element equal to A_i appeared. If such a position does not exist, let B_i = -1.
More precisely, if there exists a positive integer j such that A_i = A_j and j < i, let B_i be the largest such j. If no such j exists, let B_i = -1.
- Let B_i be the most recent position before i where an element equal to A_i appeared. If such a position does not exist, let B_i = -1.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N
Output
Print the elements of B in one line, separated by spaces.
Sample Input 1
5 1 2 1 1 3
Sample Output 1
-1 -1 1 3 -1
- i = 1: There is no 1 before A_1 = 1, so B_1 = -1.
- i = 2: There is no 2 before A_2 = 2, so B_2 = -1.
- i = 3: The most recent occurrence of 1 before A_3 = 1 is A_1, so B_3 = 1.
- i = 4: The most recent occurrence of 1 before A_4 = 1 is A_3, so B_4 = 3.
- i = 5: There is no 3 before A_5 = 3, so B_5 = -1.
Sample Input 2
4 1 1000000000 1000000000 1
Sample Output 2
-1 -1 2 1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
回転テーブルの周りに人 0、人 1、\ldots、人 N-1 がこの順番で反時計回りに等間隔で並んでいます。また、人 i の目の前には料理 p_i が置かれています。
あなたは次の操作を 0 回以上何度でも行うことが出来ます。
- 回転テーブルを反時計回りに 1 周の \frac{1}{N} だけ回す。これによって、(この操作の直前に)人 i の目の前にあった料理は人 (i+1) \bmod N の目の前に移動する。
操作を完了させた後において、人 i は料理 i が人 (i-1) \bmod N、人 i、人 (i+1) \bmod N のいずれかの目の前に置かれていると喜びます。
喜ぶ人数の最大値を求めてください。
a \bmod m とは
整数 a と正整数 m に対し、a \bmod m は a-x が m の倍数となるような 0 以上 m 未満の整数 x を表します。(このような x は一意に定まることが証明できます)制約
- 3 \leq N \leq 2 \times 10^5
- 0 \leq p_i \leq N-1
- i \neq j ならば p_i \neq p_j
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
p_0 \ldots p_{N-1}
出力
答えを出力せよ。
入力例 1
4 1 2 0 3
出力例 1
4
操作を 1 回行うと下の画像のようになります。

この時、4 人が喜ぶことを以下のように確かめられます。
- 人 0 は料理 0 が人 3\ (=(0-1) \bmod 4) の目の前に置かれているので喜びます。
- 人 1 は料理 1 が人 1\ (=1) の目の前に置かれているので喜びます。
- 人 2 は料理 2 が人 2\ (=2) の目の前に置かれているので喜びます。
- 人 3 は料理 3 が人 0\ (=(3+1) \bmod 4) の目の前に置かれているので喜びます。
5 人以上が喜ぶことは無いため、答えは 4 です。
入力例 2
3 0 1 2
出力例 2
3
入力例 3
10 3 9 6 1 7 2 8 0 5 4
出力例 3
5
Score : 300 points
Problem Statement
Person 0, Person 1, \ldots, and Person (N-1) are sitting around a turntable in their counterclockwise order, evenly spaced. Dish p_i is in front of Person i on the table.
You may perform the following operation 0 or more times:
- Rotate the turntable by one N-th of a counterclockwise turn. As a result, the dish that was in front of Person i right before the rotation is now in front of Person (i+1) \bmod N.
When you are finished, Person i is happy if Dish i is in front of Person (i-1) \bmod N, Person i, or Person (i+1) \bmod N.
Find the maximum possible number of happy people.
What is a \bmod m?
For an integer a and a positive integer m, a \bmod m denotes the integer x between 0 and (m-1) (inclusive) such that (a-x) is a multiple of m. (It can be proved that such x is unique.)Constraints
- 3 \leq N \leq 2 \times 10^5
- 0 \leq p_i \leq N-1
- p_i \neq p_j if i \neq j.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
p_0 \ldots p_{N-1}
Output
Print the answer.
Sample Input 1
4 1 2 0 3
Sample Output 1
4
The figure below shows the table after one operation.

Here, there are four happy people:
- Person 0 is happy because Dish 0 is in front of Person 3\ (=(0-1) \bmod 4);
- Person 1 is happy because Dish 1 is in front of Person 1\ (=1);
- Person 2 is happy because Dish 2 is in front of Person 2\ (=2);
- Person 3 is happy because Dish 3 is in front of Person 0\ (=(3+1) \bmod 4).
There cannot be five or more happy people, so the answer is 4.
Sample Input 2
3 0 1 2
Sample Output 2
3
Sample Input 3
10 3 9 6 1 7 2 8 0 5 4
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
6 種類の文字、(, ), [, ], <, > からなる文字列 S が与えられます。
ここで、文字列 T は、以下の条件を満たすときカラフル括弧列と呼ばれます。
以下の操作を何回か(0 回でも良い)繰り返すことで、T を空文字列にできる。
- T の(連続する)部分文字列であって、
(),[],<>のいずれかであるようなものが存在するとき、そのうちの 1 つを選んで削除する。- 削除された部分文字列が T の先頭または末尾であるとき、残りの文字列を新たに T とする。
- そうでないとき、削除された前後の文字列を 1 つに連結し、新たに T とする。
S がカラフル括弧列であるか判定してください。
制約
- S は長さ 1 以上 2\times 10^5 以下の文字列
- S は
(,),[,],<,>のみからなる。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S がカラフル括弧列ならば Yes を、そうでないならば No を出力せよ。
入力例 1
([])<>()
出力例 1
Yes
S=([])<>() に対して、次のように操作を繰り返すことで空文字列にすることができます。
([])<>()の 2 文字目から 3 文字目までをとった部分文字列[]を削除し、前後を連結する。文字列は新たに()<>()となる。()<>()の 1 文字目から 2 文字目までをとった部分文字列()を削除する。文字列は新たに<>()となる。<>()の 1 文字目から 2 文字目までをとった部分文字列<>を削除する。文字列は新たに()となる。()の 1 文字目から 2 文字目までをとった部分文字列()を削除する。文字列は空文字列となる。
よって、S=([])<>() はカラフル括弧列であるため、Yes を出力します。
入力例 2
([<)]>
出力例 2
No
S=([<)]> は (), [], <> を部分列として含まないため、1 回目の操作を行うことができず、特に S はカラフル括弧列ではありません。よって、No を出力します。
入力例 3
())
出力例 3
No
S に対して操作を繰り返し、空文字列とすることはできません。
よって、S はカラフル括弧列ではないため、No を出力します。
Score : 400 points
Problem Statement
You are given a string S consisting of six types of characters: (, ), [, ], <, >.
A string T is called a colorful bracket sequence if it satisfies the following condition:
It is possible to turn T into an empty string by repeating the following operation any number of times (possibly zero):
- If there exists a contiguous substring of T that is one of
(),[], or<>, choose one such substring and delete it.- If the deleted substring was at the beginning or end of T, the remainder becomes the new T.
- Otherwise, concatenate the part before the deleted substring and the part after the deleted substring, and that becomes the new T.
Determine whether S is a colorful bracket sequence.
Constraints
- S is a string of length between 1 and 2\times 10^5, inclusive.
- S consists of
(,),[,],<,>.
Input
The input is given from Standard Input in the following format:
S
Output
If S is a colorful bracket sequence, print Yes; otherwise, print No.
Sample Input 1
([])<>()
Sample Output 1
Yes
For S=([])<>(), it is possible to turn it into an empty string by repeating the operation as follows:
- Delete the substring
[]from the 2nd to the 3rd character in([])<>(), then concatenate the parts before and after it. The string becomes()<>(). - Delete the substring
()from the 1st to the 2nd character in()<>(). The string becomes<>(). - Delete the substring
<>from the 1st to the 2nd character in<>(). The string becomes(). - Delete the substring
()from the 1st to the 2nd character in(). The string becomes empty.
Thus, S=([])<>() is a colorful bracket sequence, so print Yes.
Sample Input 2
([<)]>
Sample Output 2
No
Since S=([<)]> does not contain (), [], or <> as a contiguous substring, we cannot perform the 1st operation, and in particular S is not a colorful bracket sequence. Therefore, print No.
Sample Input 3
())
Sample Output 3
No
It is impossible to turn S into an empty string by repeating the operations.
Therefore, S is not a colorful bracket sequence, so print No.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
N 枚のカードが入ったパックが無限にあります。各パックについて、i 枚目に入っているカードは P_i\% の確率でレアです。また、各カードがレアであることは他のカードがレアであることと独立です。
これからパックを一つずつ開封していき、開封したパックに入っているすべてのカードを手に入れます。レアカードを合計 X 枚以上手に入れるまでパックを開封するとき、開封するパックの個数の期待値を求めてください。
制約
- 1 \leq N \leq 5000
- 1 \leq X \leq 5000
- 1 \leq P_i \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X P_1 P_2 \ldots P_N
出力
答えを出力せよ。
真の答えとの絶対誤差または相対誤差が 10^{-6} 以下ならば正解と判定される。
入力例 1
2 2 50 100
出力例 1
1.5000000000000000
開封するパックの個数は \frac{1}{2} の確率で 1 個、\frac{1}{2} の確率で 2 個となります。
入力例 2
2 3 40 60
出力例 2
3.2475579530543811
入力例 3
6 3 10 33 33 10 100 10
出力例 3
1.8657859189536100
Score: 475 points
Problem Statement
There are infinitely many packs, each containing N cards. In each pack, the i-th card is rare with probability P_i percent. Whether each card is rare is independent of other cards being rare.
You will now open the packs one by one, and obtain all the cards in each opened pack. When you keep opening packs until you have obtained a total of at least X rare cards, find the expected number of packs you will open.
Constraints
- 1 \leq N \leq 5000
- 1 \leq X \leq 5000
- 1 \leq P_i \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X P_1 P_2 \ldots P_N
Output
Print the answer.
Your answer will be considered correct if the absolute or relative error from the true answer is at most 10^{-6}.
Sample Input 1
2 2 50 100
Sample Output 1
1.5000000000000000
The number of packs opened will be 1 with probability \frac{1}{2}, and 2 with probability \frac{1}{2}.
Sample Input 2
2 3 40 60
Sample Output 2
3.2475579530543811
Sample Input 3
6 3 10 33 33 10 100 10
Sample Output 3
1.8657859189536100
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
整数 N,A_1,A_2,A_3 が与えられます。以下の 3 つの条件を全て満たすような正整数の組 (X_1,X_2,X_3) の個数を 998244353 で割ったあまりを求めてください。
- 全ての i で 1\leq X_i \leq N である。
- 全ての i で X_i は A_i の倍数である。
- (X_1 \oplus X_2) \oplus X_3 = 0 である。ただし、\oplus はビット単位の xor を表す。
ビット単位 xor とは
非負整数 A, B のビット単位 xor 、A \oplus B は、以下のように定義されます。- A \oplus B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
制約
- 1 \leq N \leq 10^{18}
- 1 \leq A_i \leq 10
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 A_3
出力
答えを出力せよ。
入力例 1
13 2 3 5
出力例 1
4
(X_1,X_2,X_3) が (6,3,5),(6,12,10),(12,6,10),(12,9,5) のときの 4 通りが条件を満たします。
入力例 2
1000000000000000000 1 1 1
出力例 2
426724011
入力例 3
31415926535897932 3 8 4
出力例 3
759934997
Score : 500 points
Problem Statement
You are given integers N,A_1,A_2,A_3. Find the number, modulo 998244353, of triples of positive integers (X_1,X_2,X_3) that satisfy all of the following three conditions.
- 1\leq X_i \leq N for every i.
- X_i is a multiple of A_i for every i.
- (X_1 \oplus X_2) \oplus X_3 = 0, where \oplus denotes bitwise xor.
What is bitwise xor?
The bitwise xor of non-negative integers A and B, A \oplus B, is defined as follows.- When A \oplus B is written in binary, the 2^ks place (k \geq 0) is 1 if exactly one of the 2^ks places of A and B is 1, and 0 otherwise.
Constraints
- 1 \leq N \leq 10^{18}
- 1 \leq A_i \leq 10
- All input values are integers.
Input
The Input is given from Standard Input in the following format:
N A_1 A_2 A_3
Output
Print the answer.
Sample Input 1
13 2 3 5
Sample Output 1
4
Four triples (X_1,X_2,X_3) satisfy the conditions: (6,3,5),(6,12,10),(12,6,10),(12,9,5).
Sample Input 2
1000000000000000000 1 1 1
Sample Output 2
426724011
Sample Input 3
31415926535897932 3 8 4
Sample Output 3
759934997