Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君は気象観測の研究をしています。ある地域に設置された N 個の観測地点で、同じ日の最高気温を記録しました。観測地点には 1 から N までの番号が付けられており、観測地点 i (1 \leq i \leq N) で記録された最高気温は A_i ℃でした。
高橋君は、記録された気温の中に平均値から大きく離れた観測地点がないかを調べたいと考えています。具体的には、全観測地点の気温の平均値を
\mu = \frac{A_1 + A_2 + \cdots + A_N}{N}
としたとき、各観測地点 i について |A_i - \mu|(気温と平均値の差の絶対値)を求め、この値が最も大きい観測地点の番号を出力してください。
そのような観測地点が複数ある場合は、番号が最も小さいものを出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- -100 \leq A_i \leq 100
- N は整数
- A_i は整数
入力
N A_1 A_2 \ldots A_N
- 1 行目には、観測地点の数を表す整数 N が与えられる。
- 2 行目には、各観測地点の気温を表す N 個の整数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。
出力
平均値からの差の絶対値が最も大きい観測地点の番号を 1 行で出力せよ。該当する観測地点が複数ある場合は、番号が最も小さいものを出力せよ。
入力例 1
5 20 22 21 35 23
出力例 1
4
入力例 2
7 10 12 11 13 10 -5 11
出力例 2
6
入力例 3
10 30 31 29 30 32 31 30 29 31 -10
出力例 3
10
Score : 233 pts
Problem Statement
Takahashi is conducting research on weather observation. He recorded the daily high temperature on the same day at N observation stations set up in a certain region. The observation stations are numbered from 1 to N, and the high temperature recorded at observation station i (1 \leq i \leq N) was A_i ℃.
Takahashi wants to check whether any observation station recorded a temperature that deviates significantly from the average. Specifically, let the average temperature across all observation stations be
\mu = \frac{A_1 + A_2 + \cdots + A_N}{N}
For each observation station i, compute |A_i - \mu| (the absolute difference between the temperature and the average), and output the number of the observation station for which this value is the largest.
If there are multiple such observation stations, output the one with the smallest number.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -100 \leq A_i \leq 100
- N is an integer
- A_i is an integer
Input
N A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of observation stations.
- The second line contains N integers A_1, A_2, \ldots, A_N separated by spaces, representing the temperature at each observation station.
Output
Output in one line the number of the observation station with the largest absolute difference from the average. If there are multiple such observation stations, output the one with the smallest number.
Sample Input 1
5 20 22 21 35 23
Sample Output 1
4
Sample Input 2
7 10 12 11 13 10 -5 11
Sample Output 2
6
Sample Input 3
10 30 31 29 30 32 31 30 29 31 -10
Sample Output 3
10
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 333 点
問題文
高橋君は秘密クラブの受付係をしています。クラブに入るためには、メンバーが送るメッセージの中に正しい合言葉が隠されている必要があります。
今日は N 人がクラブへの入場を希望しており、それぞれ 1 つずつメッセージを送ってきました。 i 番目の人のメッセージは英小文字からなる文字列 S_i です。
クラブの合言葉は sayounara です。文字列 S_i が部分列として sayounara を含んでいれば、その人物は正しい合言葉を知っているとみなし、入場を許可します。
ここで、文字列 T が文字列 S の部分列であるとは、 S から 0 文字以上の文字を取り除き、残った文字を元の順序のまま連結すると T が得られることを意味します。(取り除く文字は連続していなくてもかまいません。)
N 人のメッセージそれぞれについて、合言葉が含まれているかどうかを判定してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq |S_i| \leq 5 \times 10^6
- S_i は英小文字からなる文字列
- \displaystyle\sum_{i=1}^{N} |S_i| \leq 5 \times 10^6
入力
N S_1 S_2 \vdots S_N
- 1 行目には、入場希望者の人数を表す整数 N が与えられる。
- 続く N 行のうち i 行目 (1 \leq i \leq N) には、 i 番目の入場希望者のメッセージである英小文字からなる文字列 S_i が与えられる。
出力
N 行出力せよ。 i 行目 (1 \leq i \leq N) には、 S_i が部分列として sayounara を含むならば Yes を、含まないならば No を出力せよ。
入力例 1
3 sayounara xsxaxxyxouxnxaxrxa sayounarasayounara
出力例 1
Yes Yes Yes
入力例 2
4 sayonara aranouyas hello saaayyyy
出力例 2
No No No No
入力例 3
6 sayounara abcdsaefgayhibjkoulmnnopaaqrsata sayonara ssssaaaayyyyoooouuuunnnnaaarrrraaaa souynara aaaaaaaaasaaaaaaaaayaaaaaaaaaaoaaaaaaaaaaauaaaaaaaaaanaaaaaaaaaaaaaaaaaaaaaaraaaaaaaaaa
出力例 3
Yes Yes No Yes No Yes
入力例 4
10 sayounara abcdefghijklmnopqrstuvwxyz saeiyounotaruaze thisisasayounaramessage saayyyooouuunnnaarrraaa aaaaranuoyas ssayyoouunnaarraa sxaxyzoyounbara saaaaaaaayoooounaaaaara ra
出力例 4
Yes No Yes Yes Yes No Yes Yes Yes No
入力例 5
1 a
出力例 5
No
Score : 333 pts
Problem Statement
Takahashi is working as a receptionist for a secret club. To enter the club, a member's message must contain the correct password hidden within it.
Today, N people wish to enter the club, and each of them has sent one message. The message from the i-th person is a string S_i consisting of lowercase English letters.
The club's password is sayounara. If the string S_i contains sayounara as a subsequence, that person is considered to know the correct password and is permitted to enter.
Here, a string T is a subsequence of a string S means that by removing zero or more characters from S and concatenating the remaining characters in their original order, we obtain T. (The removed characters do not need to be contiguous.)
For each of the N messages, determine whether it contains the password.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq |S_i| \leq 5 \times 10^6
- S_i is a string consisting of lowercase English letters
- \displaystyle\sum_{i=1}^{N} |S_i| \leq 5 \times 10^6
Input
N S_1 S_2 \vdots S_N
- The first line contains an integer N representing the number of people wishing to enter.
- Over the following N lines, the i-th line (1 \leq i \leq N) contains a string S_i consisting of lowercase English letters, which is the message from the i-th person.
Output
Print N lines. On the i-th line (1 \leq i \leq N), print Yes if S_i contains sayounara as a subsequence, and No otherwise.
Sample Input 1
3 sayounara xsxaxxyxouxnxaxrxa sayounarasayounara
Sample Output 1
Yes Yes Yes
Sample Input 2
4 sayonara aranouyas hello saaayyyy
Sample Output 2
No No No No
Sample Input 3
6 sayounara abcdsaefgayhibjkoulmnnopaaqrsata sayonara ssssaaaayyyyoooouuuunnnnaaarrrraaaa souynara aaaaaaaaasaaaaaaaaayaaaaaaaaaaoaaaaaaaaaaauaaaaaaaaaanaaaaaaaaaaaaaaaaaaaaaaraaaaaaaaaa
Sample Output 3
Yes Yes No Yes No Yes
Sample Input 4
10 sayounara abcdefghijklmnopqrstuvwxyz saeiyounotaruaze thisisasayounaramessage saayyyooouuunnnaarrraaa aaaaranuoyas ssayyoouunnaarraa sxaxyzoyounbara saaaaaaaayoooounaaaaara ra
Sample Output 4
Yes No Yes Yes Yes No Yes Yes Yes No
Sample Input 5
1 a
Sample Output 5
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は気象データの分析をしています。
一列に並んだ N 地点の観測所があり、各観測所 i(1 \leq i \leq N)ではその日の気温 F_i が記録されています。高橋君は、気温の最大値が目立たないようにデータを平滑化したいと考えています。
平滑化処理では、連続する K 地点がすべて観測所の範囲内に収まるように整数 l(1 \leq l \leq N - K + 1)を選び、観測所 l, l+1, \ldots, l+K-1 をグループとします。そのグループ内の全地点の気温を、グループ内の算術平均値 \displaystyle\frac{F_l + F_{l+1} + \cdots + F_{l+K-1}}{K} に一斉に置き換えます。グループに含まれない地点の気温は変化しません。この操作をちょうど 1 回行います(操作を行わないという選択はできません)。
操作後の各地点の気温を F'_1, F'_2, \ldots, F'_N とします。すなわち、グループに含まれる地点 i(l \leq i \leq l+K-1)については \displaystyle F'_i = \frac{F_l + F_{l+1} + \cdots + F_{l+K-1}}{K} となり、それ以外の地点 i については F'_i = F_i となります。ここで、平均値は実数として正確に計算し、切り捨てや四捨五入は行いません。
高橋君は、l を最適に選ぶことで、操作後の気温の最大値 \displaystyle\max_{1 \leq i \leq N} F'_i をできるだけ小さくしたいです。
この最大値として考えられる最小の値を求めてください。
制約
- 1 \leq K \leq N \leq 10^6
- -10^9 \leq F_i \leq 10^9
- N, K は整数
- F_i は整数
入力
N K F_1 F_2 \ldots F_N
- 1 行目には、観測所の数を表す整数 N と、平滑化処理で選ぶ連続する地点数を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各観測所の気温を表す整数 F_1, F_2, \ldots, F_N が、スペース区切りで与えられる。
出力
平滑化処理後の気温の最大値として考えられる最小の値を 1 行で出力せよ。なお、操作における平均値の計算は正確な実数値として行うが、出力については真の値との絶対誤差または相対誤差が 10^{-6} 以下であれば正解とする。
入力例 1
5 2 3 10 4 2 8
出力例 1
8.0000000000
入力例 2
6 3 -5 0 -2 7 1 -3
出力例 2
1.6666666667
入力例 3
12 4 15 -3 22 8 7 30 -10 5 18 12 -4 25
出力例 3
25.0000000000
入力例 4
30 7 100 -50 23 75 -10 200 0 45 90 -80 60 110 -30 15 5 130 -100 70 85 -20 40 95 -60 150 10 -5 55 120 -90 35
出力例 4
150.0000000000
入力例 5
1 1 -1000000000
出力例 5
-1000000000.0000000000
Score : 366 pts
Problem Statement
Takahashi is analyzing meteorological data.
There are N observation stations arranged in a line, and each observation station i (1 \leq i \leq N) has recorded the temperature F_i for the day. Takahashi wants to smooth the data so that the maximum temperature value is less prominent.
In the smoothing process, he selects an integer l (1 \leq l \leq N - K + 1) such that K consecutive stations all fall within the range of observation stations, and groups stations l, l+1, \ldots, l+K-1 together. The temperatures of all stations in the group are simultaneously replaced with the arithmetic mean of the group \displaystyle\frac{F_l + F_{l+1} + \cdots + F_{l+K-1}}{K}. The temperatures of stations not included in the group remain unchanged. This operation is performed exactly once (choosing not to perform the operation is not allowed).
Let F'_1, F'_2, \ldots, F'_N be the temperatures at each station after the operation. That is, for stations i included in the group (l \leq i \leq l+K-1), \displaystyle F'_i = \frac{F_l + F_{l+1} + \cdots + F_{l+K-1}}{K}, and for all other stations i, F'_i = F_i. Here, the mean is computed exactly as a real number, without truncation or rounding.
Takahashi wants to choose l optimally to minimize the maximum temperature after the operation, \displaystyle\max_{1 \leq i \leq N} F'_i.
Find the minimum possible value of this maximum.
Constraints
- 1 \leq K \leq N \leq 10^6
- -10^9 \leq F_i \leq 10^9
- N, K are integers
- F_i are integers
Input
N K F_1 F_2 \ldots F_N
- The first line contains the integer N representing the number of observation stations and the integer K representing the number of consecutive stations chosen in the smoothing process, separated by a space.
- The second line contains the integers F_1, F_2, \ldots, F_N representing the temperatures at each observation station, separated by spaces.
Output
Output in one line the minimum possible value of the maximum temperature after the smoothing process. Note that while the mean in the operation is computed as an exact real number, the output will be considered correct if the absolute error or relative error from the true value is at most 10^{-6}.
Sample Input 1
5 2 3 10 4 2 8
Sample Output 1
8.0000000000
Sample Input 2
6 3 -5 0 -2 7 1 -3
Sample Output 2
1.6666666667
Sample Input 3
12 4 15 -3 22 8 7 30 -10 5 18 12 -4 25
Sample Output 3
25.0000000000
Sample Input 4
30 7 100 -50 23 75 -10 200 0 45 90 -80 60 110 -30 15 5 130 -100 70 85 -20 40 95 -60 150 10 -5 55 120 -90 35
Sample Output 4
150.0000000000
Sample Input 5
1 1 -1000000000
Sample Output 5
-1000000000.0000000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
高橋君は市役所の職員で、ある通りの街灯の管理を担当しています。
この通りには N 本の街灯が一列に並んでおり、左から順に街灯 1, 街灯 2, \ldots, 街灯 N と番号がつけられています。街灯 i(1 \leq i \leq N)には整数値のパラメータ S_i が設定されています。このパラメータは街灯の明るさを表しますが、故障している街灯では負の値になることもあります。
高橋君は、街灯 T の電球を交換するため、一時的にその街灯を消灯する必要があります。消灯中は、街灯 T の明るさは元の値 S_T にかかわらず 0 として扱われます。
市の防犯基準では、連続する K 本の街灯からなる区間を考え、その区間内の全ての街灯の明るさの最小値を「その区間の安全度」と定めています。安全度が低いほど、その区間は暗く危険であることを意味します。
高橋君は、街灯 T を消灯している間に、街灯 T を含む連続する K 本の街灯からなる全ての区間について安全度を求め、その中での最大値を把握したいと考えています。
より厳密には、以下の条件を全て満たす整数 l を考えます:
- 1 \leq l かつ l + K - 1 \leq N
- l \leq T \leq l + K - 1(区間が街灯 T を含む)
各 l に対して、区間 [l, l+K-1] の安全度を次のように定めます。l \leq i \leq l+K-1 を満たす各整数 i について、
A_i = \begin{cases} 0 & (i = T) \\ S_i & (i \neq T) \end{cases}
としたとき、A_l, A_{l+1}, \ldots, A_{l+K-1} の最小値がこの区間の安全度です。
条件を満たす全ての l について安全度を計算し、そのうちの最大値を出力してください。
なお、制約の範囲内で条件を満たす l は必ず 1 つ以上存在します。
制約
- 1 \leq N \leq 5 \times 10^5
- 1 \leq K \leq N
- 1 \leq T \leq N
- -10^9 \leq S_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数である
入力
N K T S_1 S_2 \ldots S_N
- 1 行目には、街灯の本数を表す整数 N、区間の長さを表す整数 K、消灯する街灯の番号を表す整数 T が、スペース区切りで与えられる。
- 2 行目には、各街灯の明るさを表す整数 S_1, S_2, \ldots, S_N がスペース区切りで与えられる。
出力
街灯 T を消灯したとき、街灯 T を含む連続する K 本の街灯からなる全ての区間における安全度の最大値を 1 行で出力せよ。
入力例 1
5 3 3 2 -1 7 3 1
出力例 1
0
入力例 2
6 3 4 -5 3 2 10 -3 4
出力例 2
0
入力例 3
10 4 5 3 -2 5 1 8 -4 7 2 6 -1
出力例 3
-2
入力例 4
20 5 12 4 -3 7 2 -1 8 5 -6 3 9 1 100 -2 6 4 -7 3 8 2 -5
出力例 4
-2
入力例 5
1 1 1 1000000000
出力例 5
0
Score : 466 pts
Problem Statement
Takahashi is a city hall employee responsible for managing the street lights on a certain road.
There are N street lights lined up in a row along this road, numbered from left to right as street light 1, street light 2, \ldots, street light N. Each street light i (1 \leq i \leq N) has an integer parameter S_i. This parameter represents the brightness of the street light, but it can be negative for malfunctioning street lights.
Takahashi needs to temporarily turn off street light T in order to replace its bulb. While it is turned off, the brightness of street light T is treated as 0 regardless of its original value S_T.
According to the city's safety standards, for a section consisting of K consecutive street lights, the minimum brightness among all street lights in that section is defined as the "safety level" of that section. A lower safety level means the section is darker and more dangerous.
While street light T is turned off, Takahashi wants to compute the safety level for every section of K consecutive street lights that includes street light T, and determine the maximum value among them.
More precisely, consider all integers l satisfying the following conditions:
- 1 \leq l and l + K - 1 \leq N
- l \leq T \leq l + K - 1 (the section includes street light T)
For each l, the safety level of the section [l, l+K-1] is defined as follows. For each integer i satisfying l \leq i \leq l+K-1, let
A_i = \begin{cases} 0 & (i = T) \\ S_i & (i \neq T) \end{cases}
Then the minimum value among A_l, A_{l+1}, \ldots, A_{l+K-1} is the safety level of this section.
Compute the safety level for all l satisfying the conditions, and output the maximum value among them.
Note that under the given constraints, there always exists at least one l satisfying the conditions.
Constraints
- 1 \leq N \leq 5 \times 10^5
- 1 \leq K \leq N
- 1 \leq T \leq N
- -10^9 \leq S_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers
Input
N K T S_1 S_2 \ldots S_N
- The first line contains three space-separated integers: N representing the number of street lights, K representing the length of a section, and T representing the number of the street light to be turned off.
- The second line contains space-separated integers S_1, S_2, \ldots, S_N representing the brightness of each street light.
Output
Output in a single line the maximum safety level among all sections of K consecutive street lights that include street light T, when street light T is turned off.
Sample Input 1
5 3 3 2 -1 7 3 1
Sample Output 1
0
Sample Input 2
6 3 4 -5 3 2 10 -3 4
Sample Output 2
0
Sample Input 3
10 4 5 3 -2 5 1 8 -4 7 2 6 -1
Sample Output 3
-2
Sample Input 4
20 5 12 4 -3 7 2 -1 8 5 -6 3 9 1 100 -2 6 4 -7 3 8 2 -5
Sample Output 4
-2
Sample Input 5
1 1 1 1000000000
Sample Output 5
0