Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
文字列 S,T が与えられます。S は英小文字からなり、T は S に英小文字を 1 つ挿入して作られたことがわかっています。
挿入された文字は T の先頭から何番目の文字であるか求めてください。
複数の候補が考えられる場合はいずれか 1 つを求めてください。
制約
- 1 \leq |S| \leq 5\times 10^5
- S は英小文字からなる
- T は S に英小文字を 1 つ挿入して作られた文字列である
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
答えを出力せよ。なお、答えが複数考えられる場合はどれを出力しても正解となる。
入力例 1
atcoder atcorder
出力例 1
5
T の先頭から 5 番目の文字 r
が挿入された文字です。
入力例 2
million milllion
出力例 2
5
T の先頭から 3,4,5 番目の文字のいずれかが挿入された文字です。
よって、3,4,5 のいずれかを出力すると正解となります。
入力例 3
vvwvw vvvwvw
出力例 3
3
Score : 300 points
Problem Statement
You are given strings S and T. S consists of lowercase English letters, and T is obtained by inserting a lowercase English letter into S.
Find the position of the inserted character in T.
If there are multiple candidates, find any of them.
Constraints
- 1 \leq |S| \leq 5\times 10^5
- S consists of lowercase English letters.
- T is obtained by inserting a lowercase English letter into S.
Input
The input is given from Standard Input in the following format:
S T
Output
Print an integer i, representing that the inserted character is the i-th character from the beginning of T. If there are multiple possible answers, printing any of them is accepted.
Sample Input 1
atcoder atcorder
Sample Output 1
5
The 5-th character from the beginning of T, r
, is inserted.
Sample Input 2
million milllion
Sample Output 2
5
One of the 3-rd, 4-th, and 5-th characters from the beginning of T is inserted. Thus, printing any one of 3, 4, and 5 is accepted.
Sample Input 3
vvwvw vvvwvw
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
1 から N までの番号がついた N 枚のカードが一列に並んでいて、各 i\ (1\leq i < N) に対してカード i とカード i+1 が隣り合っています。 カード i の表には A_i が、裏には B_i が書かれており、最初全てのカードは表を向いています。
今から、N 枚のカードのうち好きな枚数 (0 枚でも良い) を選んで裏返すことを考えます。 裏返すカードの選び方は 2^N 通りありますが、そのうち以下の条件を満たすものの数を 998244353 で割った余りを求めてください。
- 選んだカードを裏返した後、どの隣り合う 2 枚のカードについても、向いている面に書かれた数が相異なる。
制約
- 1\leq N \leq 2\times 10^5
- 1\leq A_i,B_i \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
答えを整数として出力せよ。
入力例 1
3 1 2 4 2 3 4
出力例 1
4
裏返すカードの番号の集合を S とします。
例えば S=\{2,3\} を選ぶと、向いている面に書かれた数はカード 1 から順に 1,2,4 となるため条件を満たします。
一方 S=\{3\} を選ぶと、向いている面に書かれた数はカード 1 から順に 1,4,4 となり、カード 2 とカード 3 の数が一致するため条件を満たしません。
条件を満たす S は \{\},\{1\},\{2\},\{2,3\} の 4 通りです。
入力例 2
4 1 5 2 6 3 7 4 8
出力例 2
16
入力例 3
8 877914575 602436426 861648772 623690081 476190629 262703497 971407775 628894325 822804784 450968417 161735902 822804784 161735902 822804784 822804784 161735902
出力例 3
48
Score : 400 points
Problem Statement
N cards, numbered 1 through N, are arranged in a line. For each i\ (1\leq i < N), card i and card (i+1) are adjacent to each other. Card i has A_i written on its front, and B_i written on its back. Initially, all cards are face up.
Consider flipping zero or more cards chosen from the N cards. Among the 2^N ways to choose the cards to flip, find the number, modulo 998244353, of such ways that:
- when the chosen cards are flipped, for every pair of adjacent cards, the integers written on their face-up sides are different.
Constraints
- 1\leq N \leq 2\times 10^5
- 1\leq A_i,B_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print the answer as an integer.
Sample Input 1
3 1 2 4 2 3 4
Sample Output 1
4
Let S be the set of card numbers to flip.
For example, when S=\{2,3\} is chosen, the integers written on their visible sides are 1,2, and 4, from card 1 to card 3, so it satisfies the condition.
On the other hand, when S=\{3\} is chosen, the integers written on their visible sides are 1,4, and 4, from card 1 to card 3, where the integers on card 2 and card 3 are the same, violating the condition.
Four S satisfy the conditions: \{\},\{1\},\{2\}, and \{2,3\}.
Sample Input 2
4 1 5 2 6 3 7 4 8
Sample Output 2
16
Sample Input 3
8 877914575 602436426 861648772 623690081 476190629 262703497 971407775 628894325 822804784 450968417 161735902 822804784 161735902 822804784 822804784 161735902
Sample Output 3
48
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
あなたは 1 以上 6 以下の整数が等確率で出るサイコロと整数 1 を持っています。
あなたは持っている整数が N 未満である間、次の操作を繰り返します。
- サイコロを振り、出た目を x とする。持っている整数に x を掛ける。
全ての操作を終了した時に、持っている整数が N に一致する確率を \text{mod }998244353 で求めてください。
確率 \text{mod }998244353 とは?
求める確率は必ず有理数となることが証明できます。 またこの問題の制約下では、その値を互いに素な 2 つの整数 P, Q を用いて \frac{P}{Q} と表したとき、R \times Q \equiv P\pmod{998244353} かつ 0 \leq R \lt 998244353 を満たす整数 R がただ一つ存在することが証明できます。この R を求めてください。制約
- 2 \leq N \leq 10^{18}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
全ての操作を終了した時に、持っている整数が N に一致する確率を \text{mod }998244353 で出力せよ。
入力例 1
6
出力例 1
239578645
操作が終了するまでの手順としてあり得る一例を挙げると次のようになります。
- はじめ, 持っている整数は 1 である。
- サイコロを振り, 2 が出る。持っている整数は 1 \times 2 = 2 になる。
- サイコロを振り, 4 が出る。持っている整数は 2 \times 4 = 8 になる。
- 持っている整数が 6 以上になったので操作を終了する。
操作がこのように進んだ場合、操作後に持っている整数は 8 であり N = 6 に一致しません。
操作後に持っている整数が 6 である確率は \frac{7}{25} です。 239578645 \times 25 \equiv 7 \pmod{998244353} より、 239578645 を出力してください。
入力例 2
7
出力例 2
0
どのような目が出ても、操作後に持っている整数が 7 になることはありません。
入力例 3
300
出力例 3
183676961
入力例 4
979552051200000000
出力例 4
812376310
Score : 500 points
Problem Statement
You have an integer 1 and a die that shows integers between 1 and 6 (inclusive) with equal probability.
You repeat the following operation while your integer is strictly less than N:
- Cast a die. If it shows x, multiply your integer by x.
Find the probability, modulo 998244353, that your integer ends up being N.
How to find a probability modulo 998244353?
We can prove that the sought probability is always rational. Additionally, under the constraints of this problem, when that value is represented as \frac{P}{Q} with two coprime integers P and Q, we can prove that there is a unique integer R such that R \times Q \equiv P\pmod{998244353} and 0 \leq R \lt 998244353. Find this R.Constraints
- 2 \leq N \leq 10^{18}
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the probability, modulo 998244353, that your integer ends up being N.
Sample Input 1
6
Sample Output 1
239578645
One of the possible procedures is as follows.
- Initially, your integer is 1.
- You cast a die, and it shows 2. Your integer becomes 1 \times 2 = 2.
- You cast a die, and it shows 4. Your integer becomes 2 \times 4 = 8.
- Now your integer is not less than 6, so you terminate the procedure.
Your integer ends up being 8, which is not equal to N = 6.
The probability that your integer ends up being 6 is \frac{7}{25}. Since 239578645 \times 25 \equiv 7 \pmod{998244353}, print 239578645.
Sample Input 2
7
Sample Output 2
0
No matter what the die shows, your integer never ends up being 7.
Sample Input 3
300
Sample Output 3
183676961
Sample Input 4
979552051200000000
Sample Output 4
812376310
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
英小文字のみからなる文字列 S が与えられます。 下記の条件を満たす空でない文字列 T の個数を 998244353 で割ったあまりを出力してください。
T を 2 つ連結して得られる文字列 TT が、S に(連続とは限らない)部分列として含まれる。
制約
- S は英小文字のみからなる長さ 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
ababbaba
出力例 1
8
問題文中の条件を満たす文字列 T は、a
、aa
、ab
、aba
、b
、ba
、bab
、bb
の 8 個です。
入力例 2
zzz
出力例 2
1
問題文中の条件を満たす文字列 T は、z
のみです。
S = S_1S_2S_3 = zzz
から、文字列 zz
を部分列として得る方法は、
S_1S_2 = zz
、S_1S_3 = zz
、S_2S_3 = zz
の 3 通りありますが、文字列 z
は答えに 1 回だけ寄与することに注意してください。
入力例 3
ppppqqppqqqpqpqppqpqqqqpppqppq
出力例 3
580
Score : 500 points
Problem Statement
You are given a string S consisting of lowercase English letters. Print the number of non-empty strings T that satisfy the following condition, modulo 998244353.
The concatenation TT of two copies of T is a subsequence of S (not necessarily contiguous).
Constraints
- S is a string consisting of lowercase English letters whose length is between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
ababbaba
Sample Output 1
8
The eight strings satisfying the condition are a
, aa
, ab
, aba
, b
, ba
, bab
, and bb
.
Sample Input 2
zzz
Sample Output 2
1
The only string satisfying the condition is z
.
Note that this string contributes to the answer just once, although there are three ways to extract the subsequence zz
from S = S_1S_2S_3 = zzz
: S_1S_2 = zz
, S_1S_3 = zz
, and S_2S_3 = zz
.
Sample Input 3
ppppqqppqqqpqpqppqpqqqqpppqppq
Sample Output 3
580