Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる文字列 S が与えられます。
S の隣り合う文字の間にそれぞれ o を挿入してできる文字列を出力してください。
制約
- S は英小文字のみからなる長さ 2 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
mtr
出力例 1
motor
入力例 2
mnclr
出力例 2
monocolor
入力例 3
oo
出力例 3
ooo
Score : 100 points
Problem Statement
You are given a string S consisting of lowercase English letters.
Output the string obtained by inserting o between each pair of adjacent characters of S.
Constraints
- S is a string of length between 2 and 10 (inclusive) consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Output the answer.
Sample Input 1
mtr
Sample Output 1
motor
Sample Input 2
mnclr
Sample Output 2
monocolor
Sample Input 3
oo
Sample Output 3
ooo
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
AtCoder王国では、1 円硬貨、10 円硬貨、100 円硬貨の 3 種類の硬貨と、1000 円紙幣が流通しています。
高橋君は 1000 円紙幣を 10^{100} 枚、硬貨を 0 枚持っている状態から買い物を N 回行いました。
i 回目の買い物では A_i 円の商品を購入しました。
支払いでは、合計金額が A_i 円以上になるような最小枚数の 1000 円紙幣のみを出し、お釣りの硬貨の合計枚数が最小となるようにお釣りを受け取りました。
N 回の買い物が全て終わった時点で高橋君が持っている各硬貨の枚数を求めてください。
制約
- 1\leq N \leq 1000
- 1\leq A_i \leq 10^5
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \dots A_N
出力
N 回の買い物が終わった時点で高橋君が持っている 1 円硬貨、 10 円硬貨、 100 円硬貨の枚数を、この順に空白区切りで出力せよ。
入力例 1
3 1296 110 1
出力例 1
13 18 24
1 回目の買い物で、高橋君は 1296 円の支払いに対し 1000 円紙幣 2 枚を出し、100 円硬貨 7 枚と 1 円硬貨 4 枚をお釣りとして受け取ります。
2 回目の買い物で、高橋君は 110 円の支払いに対し 1000 円紙幣 1 枚を出し、100 円硬貨 8 枚と 10 円硬貨 9 枚をお釣りとして受け取ります。
3 回目の買い物で、高橋君は 1 円の支払いに対し 1000 円紙幣 1 枚を出し、100 円硬貨 9 枚、 10 円硬貨 9 枚、1 円硬貨 9 枚をお釣りとして受け取ります。
3 回の買い物が終わった時点で、高橋君は 1 円硬貨を 13 枚、 10 円硬貨を 18 枚、 100 円硬貨を 24 枚持っています。
入力例 2
12 3141 592 65358 9 79 323 84 6264 3 38327 950 28
出力例 2
52 59 82
Score : 200 points
Problem Statement
In the Kingdom of AtCoder, three kinds of coins — 1-yen coins, 10-yen coins, and 100-yen coins — and 1000-yen bills are in circulation.
Takahashi made N purchases, starting from a state where he had 10^{100} 1000-yen bills and 0 coins.
In the i-th purchase, he bought an item worth A_i yen.
For the payment, he paid using only the minimum number of 1000-yen bills such that the total amount paid was at least A_i yen, and received the change so that the total number of coins received as change was minimized.
Find the number of each type of coin that Takahashi has at the point when all N purchases are finished.
Constraints
- 1\leq N \leq 1000
- 1\leq A_i \leq 10^5
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \dots A_N
Output
Output the number of 1-yen coins, 10-yen coins, and 100-yen coins that Takahashi has at the point when the N purchases are finished, in this order, separated by spaces.
Sample Input 1
3 1296 110 1
Sample Output 1
13 18 24
In the first purchase, for the payment of 1296 yen, Takahashi pays with two 1000-yen bills, and receives seven 100-yen coins and four 1-yen coins as change.
In the second purchase, for the payment of 110 yen, he pays with one 1000-yen bill, and receives eight 100-yen coins and nine 10-yen coins as change.
In the third purchase, for the payment of 1 yen, he pays with one 1000-yen bill, and receives nine 100-yen coins, nine 10-yen coins, and nine 1-yen coins as change.
At the point when the three purchases are finished, he has 13 1-yen coins, 18 10-yen coins, and 24 100-yen coins.
Sample Input 2
12 3141 592 65358 9 79 323 84 6264 3 38327 950 28
Sample Output 2
52 59 82
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個の街が一直線上に並んでいます。街には 1, 2, \ldots, N の番号が付けられており、1 \leq i \leq N-1 を満たす各整数 i について、街 i と街 i + 1 は長さ A_i の道で結ばれています。
あなたははじめ、街 S にいます。あなたは、道で結ばれた 2 つの街の間を、その道を通って移動することを繰り返すことができます。
あなたの移動距離の合計が L 以下となるように移動するとき、一連の移動で訪れる街の数として考えられる最大値を求めてください。ただし、街 S も訪れた街に含め、複数回同じ街を訪れても 1 度しか数えないものとします。
制約
- 2 \leq N \leq 8000
- 1 \leq S \leq N
- 0 \leq L \leq 10^{18}
- 1 \leq A_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N S L
A_1 A_2 \ldots A_{N - 1}
出力
答えを出力せよ。
入力例 1
6 3 10 5 2 4 1 6
出力例 1
4
あなたははじめ街 3 にいます。街 3 \to 2 \to 3 \to 4 \to 5 の順に移動をしたとき、移動距離の合計は 2 + 2 + 4 + 1 = 9 であり、訪れた街は 2, 3, 4, 5 の 4 つです。
移動距離の合計が 10 以下となるように 5 つ以上の街を訪れることはできないため、このケースに対する答えは 4 となります。
入力例 2
8 8 17 2 3 4 4 3 5 1
出力例 2
6
入力例 3
2 1 1000000000000000000 10000
出力例 3
2
入力例 4
9 6 28 5 4 9 2 3 6 1 4
出力例 4
6
Score : 300 points
Problem Statement
There are N towns arranged in a line. The towns are numbered 1, 2, \ldots, N, and for each integer i satisfying 1 \leq i \leq N-1, town i and town i + 1 are connected by a road of length A_i.
You are initially at town S. You can repeatedly move between two towns connected by a road using that road.
Find the maximum possible number of towns visited in a sequence of moves such that the total distance traveled is at most L. Here, town S is included among the towns visited, and a town visited multiple times is counted only once.
Constraints
- 2 \leq N \leq 8000
- 1 \leq S \leq N
- 0 \leq L \leq 10^{18}
- 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 S L
A_1 A_2 \ldots A_{N - 1}
Output
Output the answer.
Sample Input 1
6 3 10 5 2 4 1 6
Sample Output 1
4
You are initially at town 3. If you move in the order town 3 \to 2 \to 3 \to 4 \to 5, the total distance traveled is 2 + 2 + 4 + 1 = 9, and the towns visited are 2, 3, 4, 5, that is, four towns.
It is impossible to visit five or more towns with a total travel distance of at most 10, so the answer for this case is 4.
Sample Input 2
8 8 17 2 3 4 4 3 5 1
Sample Output 2
6
Sample Input 3
2 1 1000000000000000000 10000
Sample Output 3
2
Sample Input 4
9 6 28 5 4 9 2 3 6 1 4
Sample Output 4
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
英小文字からなる文字列 S が与えられます。以下の条件を満たす素数 P が存在するなら 1 つ求めてください。
条件: P を先頭に余分な 0 をつけない十進表記で表した文字列を T とする。|S|=|T| かつ、全ての 1\leq i< j \leq |S| に対し、S_i=S_j と T_i=T_j が同値である。
制約
- S は英小文字のみからなる長さ 1 以上 7 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
問題文中の条件を満たす素数が存在しないとき -1 と出力せよ。
存在するとき、そのような素数を 1 つ出力せよ。答えが複数ある場合、どれを出力しても正解とみなされる。
入力例 1
motor
出力例 1
10607
この他、例えば 40709 などの出力でも正解とみなされます。また、例えば 81817 は条件を満たさないため不正解となります。
入力例 2
byebye
出力例 2
-1
条件を満たす素数が存在しないときは -1 と出力してください。
入力例 3
coconut
出力例 3
1010237
Score : 400 points
Problem Statement
You are given a string S consisting of lowercase English letters. If there exists a prime number P satisfying the following condition, find one such P.
Condition: Let T be the string representing P in decimal notation without an extra leading 0. Then, |S|=|T|, and for every 1\leq i< j \leq |S|, we have S_i=S_j if and only if T_i=T_j.
Constraints
- S is a string of length between 1 and 7 (inclusive) consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
If there is no prime number satisfying the condition in the problem statement, output -1.
If one exists, output one such prime number. If there are multiple solutions, any of them will be accepted.
Sample Input 1
motor
Sample Output 1
10607
Besides this, for example, outputting 40709 would also be accepted. However, for example, 81817 does not satisfy the condition, so it would not be accepted.
Sample Input 2
byebye
Sample Output 2
-1
If there is no prime number satisfying the condition, output -1.
Sample Input 3
coconut
Sample Output 3
1010237
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
クイズ大会の予選が行われました。参加者は 1 から N の番号がついた N 人で、予選を通過できるのは最大で M 人です。
予選は K 問の 2 択クイズからなり、各問題の答えは o または x です。
参加者 i の j 問目の問題に対する回答は文字列 S_i の j 文字目として与えられます。
j 問目の問題の正解は文字列 T の j 文字目として与えられます。
予選通過者は以下の手順により決定されます。
- 最初、予選通過者および予選脱落者は 0 名であり、参加者 N 人全員が未確定者である。
- k=1,2,\dots,K の順に以下の処理を行う。
- 予選通過者と、未確定者のうち k 問目の正解者をあわせた人数が M 人以下なら、未確定者のうち k 問目の正解者全員を予選通過者とする。
- そうでないなら、未確定者のうち k 問目の不正解者全員を予選脱落者とする。
- 未確定者全員を予選脱落者とする。
Q 個のクエリが以下の形式で与えられます。順に処理してください。
- 整数 i, j が与えられる。参加者 i の j 問目の問題に対する回答を
oならxに、xならoに変更する。その後、参加者 i が予選通過できるかどうかを判定する。
なお各クエリにおける回答変更は以降のクエリを処理する際にも残り続けます。
制約
- 1 \leq M \leq N \leq 3\times 10^4
- 1 \leq K \leq 200
- S_i,T は
o,xのみからなる長さ K の文字列 - 1 \leq Q \leq 5\times 10^4
- 各クエリについて、1\leq i \leq N、1 \leq j \leq K
入力
入力は以下の形式で標準入力から与えられる。
N M K
T
S_1
\vdots
S_N
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
ここで \mathrm{query}_q は q 番目のクエリを表し、以下の形式で与えられる。
i j
出力
Q 行出力せよ。
q 行目には q 番目のクエリで指定された参加者が予選通過できるなら Yes 、できないなら No を出力せよ。
入力例 1
5 3 3 oxo oxo oxx xxo xox xoo 3 5 1 1 3 4 1
出力例 1
Yes Yes No
- 1 番目のクエリが来る前の時点では、 1 問目で参加者 1,2 が通過、 2 問目で参加者 3 が通過し、予選通過者は参加者 1,2,3 の 3 人です。
- 1 番目のクエリのあと、1 問目で参加者 1,2,5 が通過し、予選通過者は参加者 1,2,5 の 3 人になります。参加者 5 は予選通過するので
Yesを出力します。 - 2 番目のクエリのあと、変わらず 1 問目で参加者 1,2,5 が通過し、予選通過者は参加者 1,2,5 の 3 人です。参加者 1 は予選通過するので
Yesを出力します。 - 3 番目のクエリのあと、1 問目で参加者 3 が脱落、2 問目で参加者 1,2 が通過、3 問目で参加者 5 が通過し、予選通過者は変わらず参加者 1,2,5 の 3 人です。参加者 4 は予選通過しないので
Noを出力します。
入力例 2
3 1 2 ox xo oo ox 4 3 1 1 1 2 2 1 2
出力例 2
No No Yes No
入力例 3
1 1 1 o o 2 1 1 1 1
出力例 3
No Yes
Score : 475 points
Problem Statement
A preliminary round of a quiz competition was held. There are N participants, numbered 1 to N, and at most M of them can pass the preliminary round.
The preliminary round consists of K two-choice quiz questions, and the answer to each question is o or x.
Participant i's answer to the j-th question is given as the j-th character of the string S_i.
The correct answer to the j-th question is given as the j-th character of the string T.
The qualifiers are determined by the following procedure.
- Initially, the numbers of qualifiers and non-qualifiers are both 0; all N participants are undetermined.
- For k=1,2,\dots,K in this order, perform the following process.
- If the number of qualifiers plus the number of undetermined participants who answered the k-th question correctly is at most M, then all undetermined participants who answered the k-th question correctly become qualifiers.
- Otherwise, all undetermined participants who answered the k-th question incorrectly become non-qualifiers.
- All remaining undetermined participants become non-qualifiers.
You are given Q queries in the following format. Process them in order.
- Integers i and j are given. Change participant i's answer to the j-th question from
otox, or fromxtoo. Then, determine whether participant i passes the preliminary round.
The change of the answer in each query remains in effect when processing subsequent queries as well.
Constraints
- 1 \leq M \leq N \leq 3\times 10^4
- 1 \leq K \leq 200
- S_i and T are strings of length K consisting of
oandx. - 1 \leq Q \leq 5\times 10^4
- For each query, 1\leq i \leq N and 1 \leq j \leq K.
Input
The input is given from Standard Input in the following format:
N M K
T
S_1
\vdots
S_N
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
Here, \mathrm{query}_q represents the q-th query, and is given in the following format:
i j
Output
Output Q lines.
The q-th line should contain Yes if the participant specified in the q-th query passes the preliminary round, and No otherwise.
Sample Input 1
5 3 3 oxo oxo oxx xxo xox xoo 3 5 1 1 3 4 1
Sample Output 1
Yes Yes No
- Before the first query, participants 1,2 pass on the first question and participant 3 passes on the second question, so the qualifiers are the three participants 1,2,3.
- After the first query, participants 1,2,5 pass on the first question, so the qualifiers are the three participants 1,2,5. Since participant 5 passes the preliminary round, output
Yes. - After the second query, participants 1,2,5 still pass on the first question, so the qualifiers are the three participants 1,2,5. Since participant 1 passes the preliminary round, output
Yes. - After the third query, participant 3 is eliminated on the first question, participants 1,2 pass on the second question, and participant 5 passes on the third question, so the qualifiers remain the three participants 1,2,5. Since participant 4 does not pass the preliminary round, output
No.
Sample Input 2
3 1 2 ox xo oo ox 4 3 1 1 1 2 2 1 2
Sample Output 2
No No Yes No
Sample Input 3
1 1 1 o o 2 1 1 1 1
Sample Output 3
No Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
H 行 W 列のマス目があります。このマス目の上から i 行目、左から j 列目のマスをマス (i, j) と表記します。
マス目の各マスは白または黒に塗られており、S_i の j 文字目が . のときマス (i, j) は白く、# のときマス (i, j) は黒く塗られています。
あなたは、以下の操作を高々 1 回行うことができます。
- ある矩形領域を 1 つ選び、その領域内のマスをすべて黒く塗る。より形式的には、1 \leq h_1 \leq h_2 \leq H かつ 1 \leq w_1 \leq w_2 \leq W を満たす整数 h_1, h_2, w_1, w_2 を選び、h_1 \leq h \leq h_2 かつ w_1 \leq w \leq w_2 を満たすすべての整数組 (h, w) に対し、マス (h, w) を黒く塗る。
得られるマス目の状態として考えられるものの個数を求めてください。ただし、2 つのマス目の状態は、1 \leq i \leq H, 1 \leq j \leq W を満たすある整数組 (i, j) が存在し、一方の状態ではマス (i, j) が白く塗られており、もう一方の状態ではマス (i, j) が黒く塗られているときに異なるものとします。
制約
- 1 \leq H, W
- H \times W \leq 2 \times 10^5
- H, W は整数
- S_i は
.,#からなる長さ W の文字列
入力
入力は以下の形式で標準入力から与えられる。
H W S_1 S_2 \vdots S_H
出力
答えを出力せよ。
入力例 1
2 3 #.. .##
出力例 1
7
高々 1 回の操作を行って得られるマス目の状態として考えられるものは、以下の 7 通りです。
#.. ##. #.# ### #.. ##. ### .## .## .## .## ### ### ###
入力例 2
4 1 # # # #
出力例 2
1
入力例 3
5 5 ..##. ..#.# .##.# ....# ##.##
出力例 3
96
Score : 525 points
Problem Statement
There is a grid with H rows and W columns. Let the cell at the i-th row from the top and j-th column from the left be denoted as cell (i, j).
Each cell of the grid is painted white or black: cell (i, j) is white if the j-th character of S_i is ., and black if it is #.
You can perform the following operation at most once.
- Choose a rectangular region, and paint all cells within that region black. More formally, choose integers h_1, h_2, w_1, w_2 satisfying 1 \leq h_1 \leq h_2 \leq H and 1 \leq w_1 \leq w_2 \leq W, and paint cell (h, w) black for every pair of integers (h, w) satisfying h_1 \leq h \leq h_2 and w_1 \leq w \leq w_2.
Find the number of possible states of the grid that can be obtained. Here, two states of the grid are considered different if there exists a pair of integers (i, j) satisfying 1 \leq i \leq H and 1 \leq j \leq W such that cell (i, j) is painted white in one state and painted black in the other state.
Constraints
- 1 \leq H, W
- H \times W \leq 2 \times 10^5
- H and W are integers.
- S_i is a string of length W consisting of
.and#.
Input
The input is given from Standard Input in the following format:
H W S_1 S_2 \vdots S_H
Output
Output the answer.
Sample Input 1
2 3 #.. .##
Sample Output 1
7
The possible states of the grid obtainable by performing the operation at most once are the following seven:
#.. ##. #.# ### #.. ##. ### .## .## .## .## ### ### ###
Sample Input 2
4 1 # # # #
Sample Output 2
1
Sample Input 3
5 5 ..##. ..#.# .##.# ....# ##.##
Sample Output 3
96
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 575 点
問題文
2 以上の整数 N, D が与えられます。
N 以下の正整数であって D の倍数でないもののうち、正の約数の個数が最も多いものを求めてください。ただし、そのような正整数が複数存在する場合には、いずれか 1 つを出力してください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1 \leq T \leq 10
- 2 \leq D \leq N \leq 10^{18}
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
ここで、\text{case}_i は i 番目のテストケースであり、以下の形式で与えられる。
N D
出力
T 行出力せよ。i 行目には、i 番目のテストケースに対する答えを出力せよ。
入力例 1
4 10 2 17 4 2026 919 1000000000000 48
出力例 1
9 15 1680 843291048600
10 以下の正整数であって 2 の倍数でないものは 1, 3, 5, 7, 9 の 5 つであり、それぞれ正の約数の個数は 1, 2, 2, 2, 3 です。したがって、1 番目のテストケースでは 9 を出力します。
2 番目のテストケースでは、出力例の 15 のほか、6, 10, 14 のいずれかを出力しても正答となります。
Score : 575 points
Problem Statement
You are given integers N and D, each at least 2.
Among the positive integers at most N that are not multiples of D, find one with the maximum number of positive divisors. If there are multiple such positive integers, output any one of them.
You are given T test cases; solve each of them.
Constraints
- 1 \leq T \leq 10
- 2 \leq D \leq N \leq 10^{18}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
Here, \text{case}_i represents the i-th test case, and is given in the following format:
N D
Output
Output T lines. The i-th line should contain the answer for the i-th test case.
Sample Input 1
4 10 2 17 4 2026 919 1000000000000 48
Sample Output 1
9 15 1680 843291048600
The positive integers at most 10 that are not multiples of 2 are the five integers 1, 3, 5, 7, 9, and the numbers of their positive divisors are 1, 2, 2, 2, 3, respectively. Therefore, output 9 for the first test case.
For the second test case, besides 15 in the sample output, outputting any of 6, 10, 14 is also accepted.