Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正整数 N が与えられるので、
N 個の 0
と N+1 個の 1
からなる、0
と 1
が交互に並んだ文字列を出力してください。
制約
- N は整数
- 1 \leq N \leq 100
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
4
出力例 1
101010101
4 個の 0
と 5 個の 1
からなる、0
と 1
が交互に並んだ文字列は 101010101
です。
入力例 2
1
出力例 2
101
入力例 3
10
出力例 3
101010101010101010101
Score: 100 points
Problem Statement
Given a positive integer N, print a string of N zeros and N+1 ones where 0
and 1
alternate.
Constraints
- N is an integer.
- 1 \leq N \leq 100
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
4
Sample Output 1
101010101
A string of four zeros and five ones where 0
and 1
alternate is 101010101
.
Sample Input 2
1
Sample Output 2
101
Sample Input 3
10
Sample Output 3
101010101010101010101
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
1 から N までの番号がつけられた N 個の国があり、i = 1, 2, \ldots, N について、高橋君は国 i の通貨を A_i 単位持っています。
高橋君は、下記の操作を好きな回数( 0 回でも良い)繰り返します。
- まず、1 以上 N-1 以下の整数 i を選ぶ。
- その後、国 i の通貨を S_i 単位以上持っているなら、下記の行動を 1 回行う。
- 国 i の通貨を S_i 単位だけ支払い、国 (i+1) の通貨を T_i 単位だけ獲得する。
最終的に高橋君が持っている国 N の通貨の単位数としてあり得る最大値を出力してください。
制約
- 入力される値はすべて整数
- 2 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- 1 \leq T_i \leq S_i \leq 10^9
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N S_1 T_1 S_2 T_2 \vdots S_{N-1} T_{N-1}
出力
答えを出力せよ。
入力例 1
4 5 7 0 3 2 2 4 3 5 2
出力例 1
5
以下の説明では、高橋君が持っている各国の通貨の単位数を、数列 A = (A_1, A_2, A_3, A_4) として表します。はじめ、A = (5, 7, 0, 3) です。
下記の通りに 4 回操作を行うことを考えます。
- i = 2 を選び、国 2 の通貨 4 単位を支払って、国 3 の通貨 3 単位を獲得する。その結果、A = (5, 3, 3, 3) となる。
- i = 1 を選び、国 1 の通貨 2 単位を支払って、国 2 の通貨 2 単位を獲得する。その結果、A = (3, 5, 3, 3) となる。
- i = 2 を選び、国 2 の通貨 4 単位を支払って、国 3 の通貨 3 単位を獲得する。その結果、A = (3, 1, 6, 3) となる。
- i = 3 を選び、国 3 の通貨 5 単位を支払って、国 4 の通貨 2 単位を獲得する。その結果、A = (3, 1, 1, 5) となる。
このとき、最終的に高橋君が持っている国 4 の通貨の単位数は 5 であり、これが考えられる最大値です。
入力例 2
10 32 6 46 9 37 8 33 14 31 5 5 5 3 1 4 3 2 2 3 2 3 2 4 4 3 3 3 1
出力例 2
45
Score: 150 points
Problem Statement
There are N countries numbered 1 to N. For each i = 1, 2, \ldots, N, Takahashi has A_i units of the currency of country i.
Takahashi can repeat the following operation any number of times, possibly zero:
- First, choose an integer i between 1 and N-1, inclusive.
- Then, if Takahashi has at least S_i units of the currency of country i, he performs the following action once:
- Pay S_i units of the currency of country i and gain T_i units of the currency of country (i+1).
Print the maximum possible number of units of the currency of country N that Takahashi could have in the end.
Constraints
- All input values are integers.
- 2 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- 1 \leq T_i \leq S_i \leq 10^9
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N S_1 T_1 S_2 T_2 \vdots S_{N-1} T_{N-1}
Output
Print the answer.
Sample Input 1
4 5 7 0 3 2 2 4 3 5 2
Sample Output 1
5
In the following explanation, let the sequence A = (A_1, A_2, A_3, A_4) represent the numbers of units of the currencies of the countries Takahashi has. Initially, A = (5, 7, 0, 3).
Consider performing the operation four times as follows:
- Choose i = 2, pay four units of the currency of country 2, and gain three units of the currency of country 3. Now, A = (5, 3, 3, 3).
- Choose i = 1, pay two units of the currency of country 1, and gain two units of the currency of country 2. Now, A = (3, 5, 3, 3).
- Choose i = 2, pay four units of the currency of country 2, and gain three units of the currency of country 3. Now, A = (3, 1, 6, 3).
- Choose i = 3, pay five units of the currency of country 3, and gain two units of the currency of country 4. Now, A = (3, 1, 1, 5).
At this point, Takahashi has five units of the currency of country 4, which is the maximum possible number.
Sample Input 2
10 32 6 46 9 37 8 33 14 31 5 5 5 3 1 4 3 2 2 3 2 3 2 4 4 3 3 3 1
Sample Output 2
45
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
H 行 W 列のグリッドがあります。
グリッドの各マスは陸か海のどちらかであり、
その情報は H 個の長さ W の文字列 S_1, S_2, \ldots, S_H で与えられます。
上から i 行目、左から j 列目のマスを (i, j) で表すと、
S_i の j 文字目が .
のときマス (i, j) は陸であり、#
のときマス (i, j) は海です。
ここで、グリッドの外周のマス(すなわち、i = 1 、i = H 、j = 1 、j = W のうち少なくとも 1 個以上を満たすマス (i, j) )については、すべて海であることが制約として保証されます。
高橋君が乗った宇宙船が、グリッド上のあるマスに不時着してしまいました。
その後、高橋君は L
、R
、U
、D
のみからなる長さ N の文字列 T で表される手順に沿って、グリッド上を N 回移動しました。
i = 1, 2, \ldots, N について、T の i 文字目は i 回目の移動の内容を下記の通り表します。
L
のとき、左に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i, j-1) である。R
のとき、右に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i, j+1) である。U
のとき、上に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i-1, j) である。D
のとき、下に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i+1, j) である。
高橋君の移動経路上のマス(不時着したマスおよび現在いるマスを含む)はいずれも海でないことがわかっています。 高橋君が現在いるマスとしてあり得るものの個数を出力してください。
制約
- H, W, N は整数
- 3 \leq H, W \leq 500
- 1 \leq N \leq 500
- T は
L
、R
、U
、D
のみからなる長さ N の文字列 - S_i は
.
と#
のみからなる長さ W の文字列 - 高橋君が現在いるマスとしてあり得るものが少なくとも 1 個存在する。
- グリッドの外周のマスはすべて海である。
入力
入力は以下の形式で標準入力から与えられる。
H W N T S_1 S_2 \vdots S_H
出力
答えを出力せよ。
入力例 1
6 7 5 LULDR ####### #...#.# ##...## #.#...# #...#.# #######
出力例 1
2
下記の 2 つの場合がありえるため、高橋君が現在いるマスとしてあり得るものは (3, 4) と (4, 5) の 2 個です。
- マス (3, 5) に不時着し、(3, 5) \rightarrow (3, 4) \rightarrow (2, 4) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4) と移動した場合
- マス (4, 6) に不時着し、(4, 6) \rightarrow (4, 5) \rightarrow (3, 5) \rightarrow (3, 4) \rightarrow (4, 4) \rightarrow (4, 5) と移動した場合
入力例 2
13 16 9 ULURDLURD ################ ##..##.#..####.# ###.#..#.....#.# #..##..#####.### #...#..#......## ###.##.#..#....# ##.#####....##.# ###.###.#.#.#..# ######.....##..# #...#.#.######.# ##..###..#..#.## #...#.#.#...#..# ################
出力例 2
6
Score: 250 points
Problem Statement
There is a grid with H rows and W columns.
Each cell of the grid is land or sea, which is represented by H strings S_1, S_2, \ldots, S_H of length W. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left, and (i, j) is land if the j-th character of S_i is .
, and (i, j) is sea if the character is #
.
The constraints guarantee that all cells on the perimeter of the grid (that is, the cells (i, j) that satisfy at least one of i = 1, i = H, j = 1, j = W) are sea.
Takahashi's spaceship has crash-landed on a cell in the grid. Afterward, he moved N times on the grid following the instructions represented by a string T of length N consisting of L
, R
, U
, and D
. For i = 1, 2, \ldots, N, the i-th character of T describes the i-th move as follows:
L
indicates a move of one cell to the left. That is, if he is at (i, j) before the move, he will be at (i, j-1) after the move.R
indicates a move of one cell to the right. That is, if he is at (i, j) before the move, he will be at (i, j+1) after the move.U
indicates a move of one cell up. That is, if he is at (i, j) before the move, he will be at (i-1, j) after the move.D
indicates a move of one cell down. That is, if he is at (i, j) before the move, he will be at (i+1, j) after the move.
It is known that all cells along his path (including the cell where he crash-landed and the cell he is currently on) are not sea. Print the number of cells that could be his current position.
Constraints
- H, W, and N are integers.
- 3 \leq H, W \leq 500
- 1 \leq N \leq 500
- T is a string of length N consisting of
L
,R
,U
, andD
. - S_i is a string of length W consisting of
.
and#
. - There is at least one cell that could be Takahashi's current position.
- All cells on the perimeter of the grid are sea.
Input
The input is given from Standard Input in the following format:
H W N T S_1 S_2 \vdots S_H
Output
Print the answer.
Sample Input 1
6 7 5 LULDR ####### #...#.# ##...## #.#...# #...#.# #######
Sample Output 1
2
The following two cases are possible, so there are two cells that could be Takahashi's current position: (3, 4) and (4, 5).
- He crash-landed on cell (3, 5) and moved (3, 5) \rightarrow (3, 4) \rightarrow (2, 4) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4).
- He crash-landed on cell (4, 6) and moved (4, 6) \rightarrow (4, 5) \rightarrow (3, 5) \rightarrow (3, 4) \rightarrow (4, 4) \rightarrow (4, 5).
Sample Input 2
13 16 9 ULURDLURD ################ ##..##.#..####.# ###.#..#.....#.# #..##..#####.### #...#..#......## ###.##.#..#....# ##.#####....##.# ###.###.#.#.#..# ######.....##..# #...#.#.######.# ##..###..#..#.## #...#.#.#...#..# ################
Sample Output 2
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
正整数 N, M, K が与えられます。ここで、N と M は異なります。
正の整数であって、N と M のうち ちょうど一方のみ で割り切れる数のうち小さい方から K 番目のものを出力してください。
制約
- 1\leq N, M\leq 10^8
- 1\leq K\leq 10^{10}
- N\neq M
- N, M, K は整数
入力
入力は以下の形式で標準入力から与えられる。
N M K
出力
N と M のうちちょうど一方のみで割り切れる正整数のうち小さい方から K 番目のものを出力せよ。
入力例 1
2 3 5
出力例 1
9
2 と 3 のうちちょうど一方のみで割り切れる正整数は小さい方から順に 2,3,4,8,9,10,\ldots です。
ここで、6 は 2 と 3 の両方で割り切れるため条件をみたさないことに注意してください。
条件をみたす正整数のうち小さい方から 5 番目の数は 9 であるため、9 を出力します。
入力例 2
1 2 3
出力例 2
5
条件をみたす数は小さい方から順に 1,3,5,7,\ldots です。
入力例 3
100000000 99999999 10000000000
出力例 3
500000002500000000
Score: 400 points
Problem Statement
You are given three positive integers N, M, and K. Here, N and M are different.
Print the K-th smallest positive integer divisible by exactly one of N and M.
Constraints
- 1 \leq N, M \leq 10^8
- 1 \leq K \leq 10^{10}
- N \neq M
- N, M, and K are integers.
Input
The input is given from Standard Input in the following format:
N M K
Output
Print the K-th smallest positive integer divisible by exactly one of N and M.
Sample Input 1
2 3 5
Sample Output 1
9
The positive integers divisible by exactly one of 2 and 3 are 2, 3, 4, 8, 9, 10, \ldots in ascending order.
Note that 6 is not included because it is divisible by both 2 and 3.
The fifth smallest positive integer that satisfies the condition is 9, so we print 9.
Sample Input 2
1 2 3
Sample Output 2
5
The numbers that satisfy the condition are 1, 3, 5, 7, \ldots in ascending order.
Sample Input 3
100000000 99999999 10000000000
Sample Output 3
500000002500000000
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
0
と 1
のみからなる文字列であって、文字列中のどの連続する 2 文字も異なるようなものを 良い文字列 とよびます。
0
と 1
のみからなる長さ N の文字列 S が与えられます。
Q 個のクエリが与えられるので、順に処理してください。
クエリは次の 2 種類です。
1 L R
: S の L 文字目から R 文字目までの0
と1
を反転させる。すなわち、L\leq i\leq R をみたす整数 i について、S の i 文字目が0
ならば1
に、1
ならば0
に変更する。2 L R
: S の L 文字目から R 文字目までを(順番を変えずに)抜き出した長さ (R-L+1) の文字列を S' とする。S' が良い文字列ならばYes
を、そうでないならばNo
を出力する。
制約
- 1\leq N, Q\leq 5\times 10^5
- S は
0
と1
のみからなる長さ N の文字列 - 1,2 種類目のクエリについて、1\leq L\leq R\leq N
- 2 種類目のクエリが少なくとも 1 つ存在する。
- N, Q, L, R は整数
入力
入力は以下の形式で標準入力から与えられる。
N Q S query_1 query_2 \vdots query_Q
各クエリ query_i (1\leq i\leq Q) は、
1 L R
または、
2 L R
の形で与えられる。
出力
2 種類目のクエリの数を K 個として、K 行出力せよ。
i 行目には i 個目の 2 種類目のクエリに対する出力を出力せよ。
入力例 1
5 6 10100 2 1 3 2 1 5 1 1 4 2 1 5 1 3 3 2 2 4
出力例 1
Yes No Yes No
最初、S=10100
です。このとき、クエリを与えられた順に処理すると以下のようになります。
- 1 番目のクエリについて、S の 1 文字目から 3 文字目までを抜き出した文字列は S'=
101
です。これは良い文字列なのでYes
を出力します。 - 2 番目のクエリについて、S の 1 文字目から 5 文字目までを抜き出した文字列は S'=
10100
です。これは良い文字列でないのでNo
を出力します。 - 3 番目のクエリについて、S の 1 文字目から 4 文字目までの
0
と1
を反転させます。文字列 S は S=01010
となります。 - 4 番目のクエリについて、S の 1 文字目から 5 文字目までを抜き出した文字列は S'=
01010
です。これは良い文字列なのでYes
を出力します。 - 5 番目のクエリについて、S の 3 文字目の
0
と1
を反転させます。文字列 S は S=01110
となります。 - 6 番目のクエリについて、S の 2 文字目から 4 文字目までを抜き出した文字列は S'=
111
です。これは良い文字列でないのでNo
を出力します。
入力例 2
1 2 1 1 1 1 2 1 1
出力例 2
Yes
0
または 1
の 1 文字からなる文字列は良い文字列の条件をみたすことに注意してください。
Score: 450 points
Problem Statement
A string consisting of 0
and 1
is called a good string if two consecutive characters in the string are always different.
You are given a string S of length N consisting of 0
and 1
.
Q queries will be given and must be processed in order.
There are two types of queries:
1 L R
: Flip each of the L-th to R-th characters of S. That is, for each integer i satisfying L\leq i\leq R, change the i-th character of S to0
if it is1
, and vice versa.2 L R
: Let S' be the string of length (R-L+1) obtained by extracting the L-th to R-th characters of S (without changing the order). PrintYes
if S' is a good string andNo
otherwise.
Constraints
- 1\leq N, Q\leq 5\times 10^5
- S is a string of length N consisting of
0
and1
. - 1\leq L\leq R\leq N for queries of types 1 and 2.
- There is at least one query of type 2.
- N, Q, L, and R are integers.
Input
The input is given from Standard Input in the following format:
N Q S query_1 query_2 \vdots query_Q
Each query query_i (1\leq i\leq Q) is given in the form:
1 L R
or:
2 L R
Output
Let K be the number of queries of type 2. Print K lines.
The i-th line should contain the response to the i-th query of type 2.
Sample Input 1
5 6 10100 2 1 3 2 1 5 1 1 4 2 1 5 1 3 3 2 2 4
Sample Output 1
Yes No Yes No
Initially, S=10100
. When processing the queries in the order they are given, the following occurs:
- For the first query, the string obtained by extracting the 1-st to 3-rd characters of S is S'=
101
. This is a good string, so printYes
. - For the second query, the string obtained by extracting the 1-st to 5-th characters of S is S'=
10100
. This is not a good string, so printNo
. - For the third query, flip each of the 1-st to 4-th characters of S. The string S becomes S=
01010
. - For the fourth query, the string obtained by extracting the 1-st to 5-th character of S is S'=
01010
. This is a good string, so printYes
. - For the fifth query, flip the 3-rd character of S. The string S becomes S=
01110
. - For the sixth query, the string obtained by extracting the 2-nd to 4-th character of S is S'=
111
. This is not a good string, so printNo
.
Sample Input 2
1 2 1 1 1 1 2 1 1
Sample Output 2
Yes
Note that a string of a single character 0
or 1
satisfies the condition of being a good string.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
N 個の頂点と M 本の辺からなる単純な無向グラフが与えられます。 i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i と頂点 v_i を結ぶ辺です。 また、i = 1, 2, \ldots, N について、頂点 i には正整数 W_i が割り当てられており、A_i 個のコマが置かれています。
グラフ上にコマが存在する限り、下記の操作を繰り返します。
- まず、グラフ上のコマを 1 個選んで取り除き、そのコマが置かれていた頂点を x とおく。
- x に隣接するいくつかの頂点からなる(空でも良い)集合 S であって、\sum_{y \in S} W_y \lt W_x であるものを選び、S に含まれる頂点それぞれに 1 個ずつコマを置く。
操作を行う回数としてあり得る最大値を出力してください。
なお、どのように操作を行っても、有限回の操作の後にはグラフ上にコマが存在しない状態に至ることが証明出来ます。
制約
- 入力される値はすべて整数
- 2 \leq N \leq 5000
- 1 \leq M \leq \min \lbrace N(N-1)/2, 5000 \rbrace
- 1 \leq u_i, v_i \leq N
- u_i \neq v_i
- i \neq j \implies \lbrace u_i, v_i \rbrace \neq \lbrace u_j, v_j \rbrace
- 1 \leq W_i \leq 5000
- 0 \leq A_i \leq 10^9
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M W_1 W_2 \ldots W_N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
6 6 1 2 2 3 3 1 3 4 1 5 5 6 9 2 3 1 4 4 1 0 0 0 0 1
出力例 1
5
以下の説明では、各頂点にあるコマの個数を、数列 A = (A_1, A_2, \ldots, A_N) として表します。 はじめ、A = (1, 0, 0, 0, 0, 1) です。
下記の手順で操作を行うことを考えます。
- 頂点 1 にあるコマを 1 個取り除き、頂点 2, 3 にコマを 1 個ずつ置く。その結果、A = (0, 1, 1, 0, 0, 1) となる。
- 頂点 2 にあるコマを 1 個取り除く。その結果、A = (0, 0, 1, 0, 0, 1) となる。
- 頂点 6 にあるコマを 1 個取り除く。その結果、A = (0, 0, 1, 0, 0, 0) となる。
- 頂点 3 にあるコマを 1 個取り除き、頂点 2 にコマを 1 個置く。その結果、A = (0, 1, 0, 0, 0, 0) となる。
- 頂点 2 にあるコマを 1 個取り除く。その結果、A = (0, 0, 0, 0, 0, 0) となる。
上記の手順で操作を行う回数は 5 回であり、これが操作を行う回数としてあり得る最大値です。
入力例 2
2 1 1 2 1 2 0 0
出力例 2
0
この入力例では、はじめからグラフ上にコマが存在しません。
入力例 3
10 20 4 8 1 10 1 7 5 9 9 10 8 10 7 5 1 4 7 3 8 7 2 8 5 8 4 2 5 1 7 2 8 3 3 4 8 9 7 10 2 3 25 5 1 1 16 5 98 3 21 1 35 39 32 11 35 37 14 29 36 1
出力例 3
1380
Score: 475 points
Problem Statement
You are given a simple undirected graph consisting of N vertices and M edges. For i = 1, 2, \ldots, M, the i-th edge connects vertices u_i and v_i. Also, for i = 1, 2, \ldots, N, vertex i is assigned a positive integer W_i, and there are A_i pieces placed on it.
As long as there are pieces on the graph, repeat the following operation:
- First, choose and remove one piece from the graph, and let x be the vertex on which the piece was placed.
- Choose a (possibly empty) set S of vertices adjacent to x such that \sum_{y \in S} W_y \lt W_x, and place one piece on each vertex in S.
Print the maximum number of times the operation can be performed.
It can be proved that, regardless of how the operation is performed, there will be no pieces on the graph after a finite number of iterations.
Constraints
- All input values are integers.
- 2 \leq N \leq 5000
- 1 \leq M \leq \min \lbrace N(N-1)/2, 5000 \rbrace
- 1 \leq u_i, v_i \leq N
- u_i \neq v_i
- i \neq j \implies \lbrace u_i, v_i \rbrace \neq \lbrace u_j, v_j \rbrace
- 1 \leq W_i \leq 5000
- 0 \leq A_i \leq 10^9
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M W_1 W_2 \ldots W_N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
6 6 1 2 2 3 3 1 3 4 1 5 5 6 9 2 3 1 4 4 1 0 0 0 0 1
Sample Output 1
5
In the following explanation, let A = (A_1, A_2, \ldots, A_N) represent the numbers of pieces on the vertices. Initially, A = (1, 0, 0, 0, 0, 1).
Consider performing the operation as follows:
- Remove one piece from vertex 1 and place one piece each on vertices 2 and 3. Now, A = (0, 1, 1, 0, 0, 1).
- Remove one piece from vertex 2. Now, A = (0, 0, 1, 0, 0, 1).
- Remove one piece from vertex 6. Now, A = (0, 0, 1, 0, 0, 0).
- Remove one piece from vertex 3 and place one piece on vertex 2. Now, A = (0, 1, 0, 0, 0, 0).
- Remove one piece from vertex 2. Now, A = (0, 0, 0, 0, 0, 0).
In this procedure, the operation is performed five times, which is the maximum possible number of times.
Sample Input 2
2 1 1 2 1 2 0 0
Sample Output 2
0
In this sample input, there are no pieces on the graph from the beginning.
Sample Input 3
10 20 4 8 1 10 1 7 5 9 9 10 8 10 7 5 1 4 7 3 8 7 2 8 5 8 4 2 5 1 7 2 8 3 3 4 8 9 7 10 2 3 25 5 1 1 16 5 98 3 21 1 35 39 32 11 35 37 14 29 36 1
Sample Output 3
1380
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 575 点
問題文
長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
k=1,2,\ldots,N について次の問題を解いてください。
- k\leq r\leq N をみたす整数 r を選んだ時、数列 A の k 項目から r 項目までの平均値としてあり得る最大値を求めよ。
ここで、数列 A の k 項目から r 項目までの平均値は \frac{1}{r-k+1}\displaystyle\sum_{i=k}^r A_i で定義される値である。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq A_i\leq 10^6
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
N 行出力せよ。
i 行目 (1\leq i\leq N) には、k=i のときの問題の答えを出力せよ。
出力は、すべての行の出力について、その行の出力の真の値との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。
入力例 1
5 1 1 4 5 3
出力例 1
2.80000000 3.33333333 4.50000000 5.00000000 3.00000000
k=1 のときについて、r としてあり得るのは r=1,2,3,4,5 であり、それぞれの時の平均値は、
- \frac{1}{1}=1
- \frac{1}{2}(1+1)=1
- \frac{1}{3}(1+1+4)=2
- \frac{1}{4}(1+1+4+5)=2.75
- \frac{1}{5}(1+1+4+5+3)=2.8
となります。よって、r=5 のときが最大であり、k=1 のときの答えは 2.8 となります。
同様に k=2,3,4,5 のときはそれぞれ r=4,4,4,5 としたときが最大であり、その値は \frac{10}{3}=3.333\ldots, \frac{9}{2}=4.5, \frac{5}{1}=5, \frac{3}{1}=3 となります。
入力例 2
3 999999 1 1000000
出力例 2
999999.00000000 500000.50000000 1000000.00000000
Score: 575 points
Problem Statement
You are given a sequence A=(A_1,A_2,\ldots,A_N) of length N.
For each k=1,2,\ldots,N, solve the following problem:
- Find the maximum possible average value of the k-th to r-th terms of the sequence A when choosing an integer r such that k\leq r\leq N.
Here, the average value of the k-th to r-th term of the sequence A is defined as \frac{1}{r-k+1}\displaystyle\sum_{i=k}^r A_i.
Constraints
- 1\leq N\leq 2\times 10^5
- 1\leq A_i\leq 10^6
- 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 N lines.
The i-th line (1\leq i\leq N) should contain the answer to the problem for k=i.
Your output will be considered correct if, for every line, the absolute or relative error of the printed value from the true value is at most 10^{-6}.
Sample Input 1
5 1 1 4 5 3
Sample Output 1
2.80000000 3.33333333 4.50000000 5.00000000 3.00000000
For k=1, the possible choices for r are r=1,2,3,4,5, and the average value for each of them is:
- \frac{1}{1}=1
- \frac{1}{2}(1+1)=1
- \frac{1}{3}(1+1+4)=2
- \frac{1}{4}(1+1+4+5)=2.75
- \frac{1}{5}(1+1+4+5+3)=2.8
Thus, the maximum is achieved when r=5, and the answer for k=1 is 2.8.
Similarly, for k=2,3,4,5, the maximum is achieved when r=4,4,4,5, respectively, with the values of \frac{10}{3}=3.333\ldots, \frac{9}{2}=4.5, \frac{5}{1}=5, \frac{3}{1}=3.
Sample Input 2
3 999999 1 1000000
Sample Output 2
999999.00000000 500000.50000000 1000000.00000000