Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
円周率の小数第 100 位までの値は
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
です。
1 以上 100 以下の整数 N が与えられます。
円周率を小数第 N 位まで出力してください。
より厳密には、円周率を小数第 N+1 位で切り捨て、末尾の 0
を取り除かずに出力してください。
制約
- 1\leq N\leq 100
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
円周率を小数第 N 位まで 1 行で出力せよ。
入力例 1
2
出力例 1
3.14
円周率を小数第 2+1 位で切り捨てると値は 3.14
になります。
よって、3.14
を出力してください。
入力例 2
32
出力例 2
3.14159265358979323846264338327950
末尾の 0
は取り除かずに出力してください。
入力例 3
100
出力例 3
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Score : 100 points
Problem Statement
The number pi to the 100-th decimal place is
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
.
You are given an integer N between 1 and 100, inclusive.
Print the value of pi to the N-th decimal place.
More precisely, truncate the value of pi to N decimal places and print the result without removing the trailing 0
s.
Constraints
- 1\leq N\leq 100
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the value of pi to the N-th decimal place in a single line.
Sample Input 1
2
Sample Output 1
3.14
Truncating the value of pi to 2 decimal places results in 3.14
. Thus, you should print 3.14
.
Sample Input 2
32
Sample Output 2
3.14159265358979323846264338327950
Do not remove the trailing 0
s.
Sample Input 3
100
Sample Output 3
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
あるスポーツ大会は西暦年を 4 で割った余りが 2 である年の 6 月に開催されます。
現在が西暦 Y 年の 1 月である時、このスポーツ大会が次に開催されるのは西暦何年になるかを求めてください。
制約
- 2000 \leq Y \leq 3000
- Y は整数
入力
入力は以下の形式で標準入力から与えられる。
Y
出力
答えを出力せよ。
入力例 1
2022
出力例 1
2022
2022 は 4 で割った余りが 2 なので、現在が西暦 2022 年の 1 月である時、次の開催は同年の 6 月です。
入力例 2
2023
出力例 2
2026
入力例 3
3000
出力例 3
3002
Score : 100 points
Problem Statement
A sport event is held in June of every year whose remainder when divided by 4 is 2.
Suppose that it is now January of the year Y. In what year will this sport event be held next time?
Constraints
- 2000 \leq Y \leq 3000
- Y is an integer.
Input
Input is given from Standard Input in the following format:
Y
Output
Print the answer.
Sample Input 1
2022
Sample Output 1
2022
The remainder when 2022 is divided by 4 is 2, so if it is now January of 2022, the next games will be held in June of the same year.
Sample Input 2
2023
Sample Output 2
2026
Sample Input 3
3000
Sample Output 3
3002
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
いろはちゃんは長さ N ( N \ge 1 ) の正整数列 A=(A_1,A_2,\dots,A_N) を持っています。
いろはちゃんは A を使って、次のように文字列 S を生成しました。
- S=
|
から始める。 - i=1,2,\dots,N の順に、次の操作を行う。
- S の末尾に
-
を A_i 個追加する。 - その後、 S の末尾に
|
を 1 個追加する。
- S の末尾に
生成された文字列 S が与えられるので、正整数列 A を復元してください。
制約
- S は問題文中の方法で生成された長さ 3 以上 100 以下の文字列
- A は長さ 1 以上の正整数列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを以下の形式で、 1 行に空白区切りで出力せよ。
A_1 A_2 \dots A_N
入力例 1
|---|-|----|-|-----|
出力例 1
3 1 4 1 5
S= |---|-|----|-|-----|
が生成されるような A は (3,1,4,1,5) です。
入力例 2
|----------|
出力例 2
10
入力例 3
|-|-|-|------|
出力例 3
1 1 1 6
Score : 200 points
Problem Statement
Iroha has a sequence of positive integers A = (A_1, A_2, \dots, A_N) of length N (N \ge 1).
She generated a string S using A as follows:
- Start with S =
|
. - For i = 1, 2, \dots, N, perform the following operations in order:
- Append A_i copies of
-
to the end of S. - Then, append one
|
to the end of S.
- Append A_i copies of
Given the generated string S, reconstruct the sequence A.
Constraints
- S is a string of length between 3 and 100, inclusive, generated by the method in the problem statement.
- A is a sequence of positive integers of length at least 1.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer in the following format, with elements separated by spaces in a single line:
A_1 A_2 \dots A_N
Sample Input 1
|---|-|----|-|-----|
Sample Output 1
3 1 4 1 5
S = |---|-|----|-|-----|
is generated by A = (3, 1, 4, 1, 5).
Sample Input 2
|----------|
Sample Output 2
10
Sample Input 3
|-|-|-|------|
Sample Output 3
1 1 1 6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の正整数列 A = (A_1, A_2, \dots ,A_N) が与えられます。高橋くんは、以下の操作を A に含まれる正の要素の個数が 1 つ以下になるまで繰り返します。
- A を要素の降順に並び替える。それから、 A_1, A_2 を 1 減らす。
高橋くんが操作をする回数を求めてください。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \cdots A_N
出力
答えを出力せよ。
入力例 1
4 1 2 3 3
出力例 1
4
操作は以下のように進みます。
- 1 回目の操作で A = (2, 2, 2, 1) となる。
- 2 回目の操作で A = (1, 1, 2, 1) となる。
- 3 回目の操作で A = (1, 0, 1, 1) となる。
- 4 回目の操作で A = (0, 0, 1, 0) となる。A に含まれる正の要素の個数が 1 つ以下になったので、ここで操作を終了する。
入力例 2
3 1 1 100
出力例 2
2
Score : 200 points
Problem Statement
You are given a sequence of N positive integers A = (A_1, A_2, \dots ,A_N). Takahashi repeats the following operation until A contains one or fewer positive elements:
- Sort A in descending order. Then, decrease both A_1 and A_2 by 1.
Find the number of times he performs this operation.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \cdots A_N
Output
Print the answer.
Sample Input 1
4 1 2 3 3
Sample Output 1
4
The process goes as follows:
- After the 1st operation, A is (2, 2, 2, 1).
- After the 2nd operation, A is (1, 1, 2, 1).
- After the 3rd operation, A is (1, 0, 1, 1).
- After the 4th operation, A is (0, 0, 1, 0). A no longer contains more than one positive elements, so the process ends here.
Sample Input 2
3 1 1 100
Sample Output 2
2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
AtCoder 王国では、これから N 日間のお祭りが開催されます。そのうち、A_1 日目、A_2 日目、\dots、A_M 日目の M 日では花火が上がります。ここで、お祭りの最終日には花火が上がることが保証されます。(つまり、A_M=N が保証されます。)
i=1,2,\dots,N に対して、以下の問題を解いてください。
- i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後か?ただし、i 日目に花火が上がる場合 0 日後とする。
制約
- 1 \le M \le N \le 2 \times 10^5
- 1 \le A_1 < A_2 < \dots < A_M = N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_M
出力
N 行出力せよ。
i(1 \le i \le N) 行目には、i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後かを整数として出力せよ。
入力例 1
3 2 2 3
出力例 1
1 0 0
AtCoder 王国ではお祭りを 3 日間開催し、2,3 日目に花火が上がります。
- 1 日目以降で初めて花火が上がるのは 2 日目なので、1 日目から数えて 1 日後です。
- 2 日目以降で初めて花火が上がるのは 2 日目なので、2 日目から数えて 0 日後です。
- 3 日目以降で初めて花火が上がるのは 3 日目なので、3 日目から数えて 0 日後です。
入力例 2
8 5 1 3 4 7 8
出力例 2
0 1 0 0 2 1 0 0
Score : 250 points
Problem Statement
The AtCoder Kingdom holds a festival for N days. On M of these days, namely on the A_1-th, A_2-th, \dots, A_M-th days, fireworks will be launched. It is guaranteed that fireworks will be launched on the last day of the festival. (In other words, A_M=N is guaranteed.)
For each i=1,2,\dots,N, solve the following problem.
- How many days later from the i-th day will fireworks be launched for the first time on or after the i-th day? If fireworks are launched on the i-th day, it is considered to be 0 days later.
Constraints
- 1 \le M \le N \le 2 \times 10^5
- 1 \le A_1 < A_2 < \dots < A_M = 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
Output
Print N lines.
The i-th line (1 \le i \le N) should contain an integer representing the number of days from the i-th day until fireworks are launched for the first time on or after the i-th day.
Sample Input 1
3 2 2 3
Sample Output 1
1 0 0
The kingdom holds a festival for 3 days, and fireworks are launched on the 2-nd and 3-rd days.
- From the 1-st day, the first time fireworks are launched is the 2-nd day of the festival, which is 1 day later.
- From the 2-nd day, the first time fireworks are launched is the 2-nd day of the festival, which is 0 days later.
- From the 3-rd day, the first time fireworks are launched is the 3-rd day of the festival, which is 0 days later.
Sample Input 2
8 5 1 3 4 7 8
Sample Output 2
0 1 0 0 2 1 0 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。
制約
- K は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22
のような指数表記や、 0523
のような先頭に不要な 0 を付けたような表記は許されない。
入力例 1
3
出力例 1
22
10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。
入力例 2
11
出力例 2
2022
入力例 3
923423423420220108
出力例 3
220022020000202020002022022000002020002222002200002022002200
たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。
Score : 300 points
Problem Statement
Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.
Constraints
- K is an integer between 1 and 10^{18} (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22
, for example, or unnecessary leading zeros such as 0523
are not allowed.
Sample Input 1
3
Sample Output 1
22
The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.
Sample Input 2
11
Sample Output 2
2022
Sample Input 3
923423423420220108
Sample Output 3
220022020000202020002022022000002020002222002200002022002200
Note that the exact value of the answer must be printed as an integer, even if it is big.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
ある星には N 人の宇宙人がおり、全員未成年です。
i 人目の宇宙人は現在 A_i 個の石を所持しており、ちょうど i 年後に成人します。
この星では誰かが成人するとき、石を 1 個以上所持している成人全員が、成人する宇宙人に成人祝いとして石を 1 個渡します。
N 年後に各宇宙人が所持している石の個数を求めてください。
ただし、今後新たな宇宙人は産まれないものとします。
制約
- 1 \leq N \leq 5 \times 10^5
- 0 \leq A_i \leq 5 \times 10^5
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
N 年後に i 人目の宇宙人が所持している石の個数を B_i として B_1, B_2, \ldots, B_N をこの順に空白区切りで出力せよ。
入力例 1
4 5 0 9 3
出力例 1
2 0 10 5
i 人目の宇宙人が持っている石の個数を C_i で表します。
はじめ (C_1, C_2, C_3, C_4) = (5, 0, 9, 3) です。
1 年後には (C_1, C_2, C_3, C_4) = (5, 0, 9, 3) となります。
2 年後には (C_1, C_2, C_3, C_4) = (4, 1, 9, 3) となります。
3 年後には (C_1, C_2, C_3, C_4) = (3, 0, 11, 3) となります。
4 年後には (C_1, C_2, C_3, C_4) = (2, 0, 10, 5) となります。
入力例 2
5 4 6 7 2 5
出力例 2
0 4 7 4 9
入力例 3
10 2 9 1 2 0 4 6 7 1 5
出力例 3
0 2 0 0 0 4 7 10 4 10
Score : 400 points
Problem Statement
On a certain planet, there are N aliens, all of whom are minors.
The i-th alien currently has A_i stones, and will become an adult exactly i years later.
When someone becomes an adult on this planet, every adult who has at least one stone gives exactly one stone as a congratulatory gift to the alien who has just become an adult.
Find how many stones each alien will have after N years.
Assume that no new aliens will be born in the future.
Constraints
- 1 \leq N \leq 5 \times 10^5
- 0 \leq A_i \leq 5 \times 10^5
- 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
Let B_i be the number of stones owned by the i-th alien after N years. Print B_1, B_2, \ldots, B_N in this order, separated by spaces.
Sample Input 1
4 5 0 9 3
Sample Output 1
2 0 10 5
Let C_i be the number of stones that the i-th alien has at a given time.
Initially, (C_1, C_2, C_3, C_4) = (5, 0, 9, 3).
After 1 year, (C_1, C_2, C_3, C_4) = (5, 0, 9, 3).
After 2 years, (C_1, C_2, C_3, C_4) = (4, 1, 9, 3).
After 3 years, (C_1, C_2, C_3, C_4) = (3, 0, 11, 3).
After 4 years, (C_1, C_2, C_3, C_4) = (2, 0, 10, 5).
Sample Input 2
5 4 6 7 2 5
Sample Output 2
0 4 7 4 9
Sample Input 3
10 2 9 1 2 0 4 6 7 1 5
Sample Output 3
0 2 0 0 0 4 7 10 4 10
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
ベルトコンベアに載って 10^{100} 個のじゃがいもが 1 個ずつ流れてきます。流れてくるじゃがいもの重さは長さ N の数列 W = (W_0, \dots, W_{N-1}) で表され、i \, (1 \leq i \leq 10^{100}) 番目に流れてくるじゃがいもの重さは W_{(i-1) \bmod N} です。ここで、(i-1) \bmod N は i - 1 を N で割った余りを表します。
高橋君は、まず空の箱を用意し、次のルールに従ってじゃがいもを順番に箱に詰めていきます。
- じゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和が X 以上になったら、その箱には蓋をし、新たに空の箱を用意する。
Q 個のクエリが与えられます。i \, (1 \leq i \leq Q) 番目のクエリでは、正整数 K_i が与えられるので、K_i 番目に蓋をされた箱に入っているじゃがいもの個数を求めてください。問題の制約下で、蓋をされた箱が K_i 個以上存在することが証明できます。
制約
- 1 \leq N, Q \leq 2 \times 10^5
- 1 \leq X \leq 10^9
- 1 \leq W_i \leq 10^9 \, (0 \leq i \leq N - 1)
- 1 \leq K_i \leq 10^{12} \, (1 \leq i \leq Q)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q X W_0 W_1 \ldots W_{N-1} K_1 \vdots K_Q
出力
Q 行出力せよ。i \, (1 \leq i \leq Q) 行目には、i 番目のクエリへの答えを出力せよ。
入力例 1
3 2 5 3 4 1 1 2
出力例 1
2 3
2 つの箱に蓋をするまでの高橋くんの行動は以下の通りです。
- 空の箱を用意する。
- 1 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 3 である。
- 2 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 3 + 4 = 7 であり、X = 5 以上になったのでこの箱には蓋をする。
- 新たに空の箱を用意する。
- 3 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 1 である。
- 4 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 1 + 3 = 4 である。
- 5 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 1 + 3 + 4 = 8 であり、X = 5 以上になったのでこの箱には蓋をする。
1 番目に蓋をされた箱には 2 つのじゃがいもが入っており、2 番目に蓋をされた箱には 3 つのじゃがいもが入っています。
入力例 2
10 5 20 5 8 5 9 8 7 4 4 8 2 1 1000 1000000 1000000000 1000000000000
出力例 2
4 5 5 5 5
Score : 500 points
Problem Statement
10^{100} potatoes are coming from a conveyor belt one by one. The weights of the potatoes are described by a sequence W = (W_0, \dots, W_{N-1}) of length N: the weight of the i-th potato coming is W_{(i-1) \bmod N}, where (i-1) \bmod N denotes the remainder when i - 1 is divided by N.
Takahashi will prepare an empty box and then pack the potatoes in order, as follows.
- Pack the incoming potato into the box. If the total weight of the potatoes in the box is now X or greater, seal that box and prepare a new empty box.
You are given Q queries. In the i-th query (1 \leq i \leq Q), given a positive integer K_i, find the number of potatoes in the K_i-th box to be sealed. It can be proved that, under the Constraints of the problem, there will be at least K_i sealed boxes.
Constraints
- 1 \leq N, Q \leq 2 \times 10^5
- 1 \leq X \leq 10^9
- 1 \leq W_i \leq 10^9 \, (0 \leq i \leq N - 1)
- 1 \leq K_i \leq 10^{12} \, (1 \leq i \leq Q)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q X W_0 W_1 \ldots W_{N-1} K_1 \vdots K_Q
Output
Print Q lines. The i-th line (1 \leq i \leq Q) should contain the answer to the i-th query.
Sample Input 1
3 2 5 3 4 1 1 2
Sample Output 1
2 3
Before sealing the 2-nd box, Takahashi will do the following:
- Prepare an empty box.
- Pack the 1-st potato into the box. Now, the total weight of potatoes in the box is 3.
- Pack the 2-nd potato into the box. Now, the total weight of potatoes in the box is 3 + 4 = 7, which is not less than X = 5, so seal this box.
- Prepare a new empty box.
- Pack the 3-rd potato into the box. Now, the total weight of potatoes in the box is 1.
- Pack the 4-th potato into the box. Now, the total weight of potatoes in the box is 1 + 3 = 4.
- Pack the 5-th potato into the box. Now, the total weight of potatoes in the box is 1 + 3 + 4 = 8, which is not less than X = 5, so seal this box.
The 1-st box sealed contains 2 potatoes, and the 2-nd box sealed contains 3 potatoes.
Sample Input 2
10 5 20 5 8 5 9 8 7 4 4 8 2 1 1000 1000000 1000000000 1000000000000
Sample Output 2
4 5 5 5 5
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
2 つの文字列 X,Y に対して、その類似度 f(X,Y) を、X と Y を先頭から見て一致している文字数とします。
例えば abc
と axbc
の類似度は 1 、aaa
と aaaa
の類似度は 3 です。
長さ N の文字列 S が与えられます。S の i 文字目以降からなる文字列を S_i とします。k=1,\ldots,N のそれぞれについて、f(S_k,S_1)+f(S_k,S_2)+\ldots+f(S_k,S_N) を求めてください。
制約
- 1 \leq N \leq 10^6
- S は英小文字のみからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
N 行出力せよ。
i 行目には k=i の問題の答えを出力せよ。
入力例 1
3 abb
出力例 1
3 3 2
S_1,S_2,S_3 はそれぞれ abb
, bb
, b
です。
- k=1 のとき f(S_1,S_1)+f(S_1,S_2)+f(S_1,S_3)=3+0+0=3
- k=2 のとき f(S_2,S_1)+f(S_2,S_2)+f(S_2,S_3)=0+2+1=3
- k=3 のとき f(S_3,S_1)+f(S_3,S_2)+f(S_3,S_3)=0+1+1=2
入力例 2
11 mississippi
出力例 2
11 16 14 12 13 11 9 7 4 3 4
Score : 500 points
Problem Statement
Let the similarity f(X,Y) between two strings X and Y be the length of their longest common prefix.
For example, the similarity between abc
and axbc
is 1, and the similarity between aaa
and aaaa
is 3.
You are given a string S of length N. Let S_i be the suffix of S beginning with the i-th character of S. For each k=1,\ldots,N, find f(S_k,S_1)+f(S_k,S_2)+\ldots+f(S_k,S_N).
Constraints
- 1 \leq N \leq 10^6
- S is a string of length N consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N S
Output
Print N lines.
The i-th line should contain the answer for k=i.
Sample Input 1
3 abb
Sample Output 1
3 3 2
S_1 is abb
, S_2 is bb
, and S_3 is b
.
- For k=1: f(S_1,S_1)+f(S_1,S_2)+f(S_1,S_3)=3+0+0=3.
- For k=2: f(S_2,S_1)+f(S_2,S_2)+f(S_2,S_3)=0+2+1=3.
- For k=3: f(S_3,S_1)+f(S_3,S_2)+f(S_3,S_3)=0+1+1=2.
Sample Input 2
11 mississippi
Sample Output 2
11 16 14 12 13 11 9 7 4 3 4