実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
正整数からなる長さ N の数列 A=(A_1,\ldots,A_N) があります。どの隣接する 2 項の値も相異なります。
この数列に対し、次の操作によりいくつか数を挿入します。
- 数列 A のどの隣接する 2 項の差の絶対値も 1 であるとき、操作を終了する。
- 数列 A の先頭から見て、隣接する 2 項の差の絶対値が 1 でない最初の箇所を A_i,A_{i+1} とする。
- A_i < A_{i+1} ならば、A_i と A_{i+1} の間に、A_i+1,A_i+2,\ldots,A_{i+1}-1 を挿入する。
- A_i > A_{i+1} ならば、A_i と A_{i+1} の間に、A_i-1,A_i-2,\ldots,A_{i+1}+1 を挿入する。
- 手順 1 に戻る。
操作が終了したときの数列を出力してください。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_i \neq A_{i+1}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
操作が終了したときの数列の各要素を空白区切りで出力せよ。
入力例 1
4 2 5 1 2
出力例 1
2 3 4 5 4 3 2 1 2
最初、数列は (2,5,1,2) です。操作は以下のように行われます。
- 1 項目の 2 と 2 項目の 5 の間に 3,4 を挿入する。数列は (2,3,4,5,1,2) となる。
- 4 項目の 5 と 5 項目の 1 の間に 4,3,2 を挿入する。数列は (2,3,4,5,4,3,2,1,2) となる。
入力例 2
6 3 4 5 6 5 4
出力例 2
3 4 5 6 5 4
一度も挿入が行われないこともあります。
Score : 200 points
Problem Statement
We have a sequence of length N consisting of positive integers: A=(A_1,\ldots,A_N). Any two adjacent terms have different values.
Let us insert some numbers into this sequence by the following procedure.
- If every pair of adjacent terms in A has an absolute difference of 1, terminate the procedure.
- Let A_i, A_{i+1} be the pair of adjacent terms nearest to the beginning of A whose absolute difference is not 1.
- If A_i < A_{i+1}, insert A_i+1,A_i+2,\ldots,A_{i+1}-1 between A_i and A_{i+1}.
- If A_i > A_{i+1}, insert A_i-1,A_i-2,\ldots,A_{i+1}+1 between A_i and A_{i+1}.
- Return to step 1.
Print the sequence when the procedure ends.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_i \neq A_{i+1}
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the terms in the sequence when the procedure ends, separated by spaces.
Sample Input 1
4 2 5 1 2
Sample Output 1
2 3 4 5 4 3 2 1 2
The initial sequence is (2,5,1,2). The procedure goes as follows.
- Insert 3,4 between the first term 2 and the second term 5, making the sequence (2,3,4,5,1,2).
- Insert 4,3,2 between the fourth term 5 and the fifth term 1, making the sequence (2,3,4,5,4,3,2,1,2).
Sample Input 2
6 3 4 5 6 5 4
Sample Output 2
3 4 5 6 5 4
No insertions may be performed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
1 から N までの番号がついた N 人の参加者が、1 から M までの番号がついた M 問からなるコンテストに参加します。
1 以上 N 以下の整数 i 、1 以上 M 以下の整数 j について、S_i の j 番目の文字が o のとき参加者 i は問題 j を解くことが可能で、S_i の j 番目の文字が x のとき参加者 i は問題 j を解くことが不可能です。
このコンテストは、二人の参加者でペアを組んで参加します。二人が協力することで M 問全てを解くことが可能であるようなペアの個数を答えてください。
より厳密には、1\leq x < y\leq N を満たす整数の組 (x,y) であって、 1 以上 M 以下の任意の整数 j について、参加者 x か参加者 y の少なくとも一方は問題 j を解くことが可能であるという条件を満たすものの個数を答えてください。
制約
- N は 2 以上 30 以下の整数
- M は 1 以上 30 以下の整数
- S_i は
o,xからなる長さ M の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
5 5 ooooo oooxx xxooo oxoxo xxxxx
出力例 1
5
参加者 1 と 2 のペア、参加者 1 と 3 のペア、参加者 1 と 4 のペア、参加者 1 と 5 のペア、参加者 2 と 3 のペアの 5 個のペアが条件を満たします。
例えば参加者 2 と 4 のペアは、問題 4 が解けないので条件を満たしません。
入力例 2
3 2 ox xo xx
出力例 2
1
入力例 3
2 4 xxxx oxox
出力例 3
0
Score : 200 points
Problem Statement
N participants, numbered 1 to N, will participate in a contest with M problems, numbered 1 to M.
For an integer i between 1 and N and an integer j between 1 and M, participant i can solve problem j if the j-th character of S_i is o, and cannot solve it if that character is x.
The participants must be in pairs. Print the number of ways to form a pair of participants who can collectively solve all the M problems.
More formally, print the number of pairs (x,y) of integers satisfying 1\leq x < y\leq N such that for any integer j between 1 and M, at least one of participant x and participant y can solve problem j.
Constraints
- N is an integer between 2 and 30, inclusive.
- M is an integer between 1 and 30, inclusive.
- S_i is a string of length M consisting of
oandx.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Print the answer.
Sample Input 1
5 5 ooooo oooxx xxooo oxoxo xxxxx
Sample Output 1
5
The following five pairs satisfy the condition: participants 1 and 2, participants 1 and 3, participants 1 and 4, participants 1 and 5, and participants 2 and 3.
On the other hand, the pair of participants 2 and 4, for instance, does not satisfy the condition because they cannot solve problem 4.
Sample Input 2
3 2 ox xo xx
Sample Output 2
1
Sample Input 3
2 4 xxxx oxox
Sample Output 3
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
1 から N の番号が付いた N 人がコイントスを何回かしました。人 i は A_i 回表を出し、B_i 回裏を出したこと分かっています。
人 i のコイントスの 成功率 は \displaystyle\frac{A_i}{A_i+B_i} で定義されます。人 1,\ldots,N の番号を、成功率の高い順に並び替えてください。成功率が同じ人が複数いる場合、その中では人の番号が小さい順になるように並び替えてください。
制約
- 2\leq N \leq 2\times 10^5
- 0\leq A_i, B_i\leq 10^9
- A_i+B_i \geq 1
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 \vdots A_N B_N
出力
人 1,\ldots,N の番号を成功率の高い順に空白区切りで出力せよ。成功率が同じ人の番号は昇順に並び替えて出力せよ。
入力例 1
3 1 3 3 1 2 2
出力例 1
2 3 1
人 1 の成功率は 0.25、人 2 の成功率は 0.75、人 3 の成功率は 0.5 です。
成功率の高い順に並び替えると出力例の順番になります。
入力例 2
2 1 3 2 6
出力例 2
1 2
人 1,2 は成功率が同じなので、番号の昇順に出力することに注意してください。
入力例 3
4 999999999 1000000000 333333333 999999999 1000000000 999999997 999999998 1000000000
出力例 3
3 1 4 2
Score : 300 points
Problem Statement
N people numbered 1 through N tossed a coin several times. We know that person i's tosses resulted in A_i heads and B_i tails.
Person i's success rate of the tosses is defined by \displaystyle\frac{A_i}{A_i+B_i}. Sort people 1,\ldots,N in descending order of their success rates, with ties broken in ascending order of their assigned numbers.
Constraints
- 2\leq N \leq 2\times 10^5
- 0\leq A_i, B_i\leq 10^9
- A_i+B_i \geq 1
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 \vdots A_N B_N
Output
Print the numbers of people 1,\ldots,N in descending order of their success rates, with ties broken in ascending order of their assigned numbers.
Sample Input 1
3 1 3 3 1 2 2
Sample Output 1
2 3 1
Person 1's success rate is 0.25, person 2's is 0.75, and person 3's is 0.5.
Sort them in descending order of their success rates to obtain the order in Sample Output.
Sample Input 2
2 1 3 2 6
Sample Output 2
1 2
Note that person 1 and 2 should be printed in ascending order of their numbers, as they have the same success rates.
Sample Input 3
4 999999999 1000000000 333333333 999999999 1000000000 999999997 999999998 1000000000
Sample Output 3
3 1 4 2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。
S の空でない部分文字列であって、1 種類の文字のみからなるものの数を求めてください。 ただし、文字列として等しい部分文字列同士は、取り出し方が異なっても区別しません。
なお、S の空でない部分文字列とは、S の先頭から 0 文字以上、末尾から 0 文字以上削除して得られる文字列のうち、長さが 1 以上であるもののことをいいます。
例えば、ab や abc は abc の空でない部分文字列ですが、ac や空文字列は abc の空でない部分文字列ではありません。
制約
- 1 \leq N \leq 2\times 10^5
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の空でない部分文字列であって、1 種類の文字のみからなるものの数を出力せよ。
入力例 1
6 aaabaa
出力例 1
4
S の空でない部分文字列であって、1 種類の文字のみからなるものは a, aa, aaa, b の 4 つです。
S から a や aa を取り出す方法は 1 通りではありませんが、それぞれ 1 回ずつしか数えないことに注意してください。
入力例 2
1 x
出力例 2
1
入力例 3
12 ssskkyskkkky
出力例 3
8
Score : 300 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters.
Find the number of non-empty substrings of S that are repetitions of one character. Here, two substrings that are equal as strings are not distinguished even if they are obtained differently.
A non-empty substring of S is a string of length at least one obtained by deleting zero or more characters from the beginning and zero or more characters from the end of S. For example, ab and abc are non-empty substrings of abc, while ac and the empty string are not.
Constraints
- 1 \leq N \leq 2\times 10^5
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the number of non-empty substrings of S that are repetitions of one character.
Sample Input 1
6 aaabaa
Sample Output 1
4
The non-empty substrings of S that are repetitions of one character are a, aa, aaa, and b; there are four of them. Note that there are multiple ways to obtain a or aa from S, but each should only be counted once.
Sample Input 2
1 x
Sample Output 2
1
Sample Input 3
12 ssskkyskkkky
Sample Output 3
8
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N 個のステージからなるゲームがあり、i \, (1 \leq i \leq N) 番目のステージは A_i 分間のストーリー映像と B_i 分間のゲームプレイによって構成されます。
初めて i 番目のステージをクリアするためにはストーリー映像の視聴とゲームプレイを両方行う必要がありますが、二回目以降はストーリー映像をスキップすることができるので、ゲームプレイのみでクリアすることができます。
初めから遊べるのは 1 番目のステージのみですが、i \, (1 \leq i \leq N - 1) 番目のステージをクリアすることにより、i+1 番目のステージも遊べるようになります。
合計 X 回ステージをクリアするために必要な時間の最小値を求めてください。ただし、同じステージを複数回クリアしたとしても、全てクリア回数に数えられます。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq 10^9 \, (1 \leq i \leq N)
- 1 \leq X \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 B_1 \vdots A_N B_N
出力
答えを出力せよ。
入力例 1
3 4 3 4 2 3 4 2
出力例 1
18
例えば、次のようにして 18 分で 4 回クリアすることができます。
- ステージ 1 をクリアする。A_1 + B_1 = 7 分かかる。
- ステージ 2 をクリアする。A_2 + B_2 = 5 分かかる。
- ステージ 2 を再びクリアする。B_2 = 3 分かかる。
- ステージ 2 を再びクリアする。B_2 = 3 分かかる。
17 分以内に 4 回クリアすることはできません。
入力例 2
10 1000000000 3 3 1 6 4 7 1 8 5 7 9 9 2 4 6 4 5 1 3 1
出力例 2
1000000076
Score : 400 points
Problem Statement
We have a video game consisting of N stages. The i-th stage (1 \leq i \leq N) is composed of a movie lasting A_i minutes and gameplay lasting B_i minutes.
To clear the i-th stage for the first time, one must watch the movie and do the gameplay for that stage. For the second and subsequent times, one may skip the movie and do just the gameplay.
In the beginning, only the 1-st stage is unlocked, and clearing the i-th stage (1 \leq i \leq N - 1) unlocks the (i+1)-th stage.
Find the shortest time needed to clear a stage X times in total. Here, if the same stage is cleared multiple times, all of them count.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq 10^9 \, (1 \leq i \leq N)
- 1 \leq X \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X A_1 B_1 \vdots A_N B_N
Output
Print the answer.
Sample Input 1
3 4 3 4 2 3 4 2
Sample Output 1
18
Here is one way to clear a stage 4 times in 18 minutes:
- Clear Stage 1. It takes A_1 + B_1 = 7 minutes.
- Clear Stage 2. It takes A_2 + B_2 = 5 minutes.
- Clear Stage 2 again. It takes B_2= 3 minutes.
- Clear Stage 2 again. It takes B_2= 3 minutes.
It is impossible to clear a stage 4 times within 17 minutes.
Sample Input 2
10 1000000000 3 3 1 6 4 7 1 8 5 7 9 9 2 4 6 4 5 1 3 1
Sample Output 2
1000000076