実行時間制限: 2 sec / メモリ制限: 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
実行時間制限: 2 sec / メモリ制限: 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
実行時間制限: 2 sec / メモリ制限: 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.
実行時間制限: 2 sec / メモリ制限: 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
実行時間制限: 2 sec / メモリ制限: 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