Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
A, B, C からなる長さ N の文字列 S が与えられます。
S の中で ABC が(連続な)部分文字列として初めて現れる位置を答えてください。すなわち、以下の条件を全て満たす整数 n のうち最小のものを答えてください。
- 1 \leq n \leq N - 2
- S の n 文字目から n+2 文字目までを取り出して出来る文字列は
ABCである。
ただし、ABC が S に現れない場合は -1 を出力してください。
制約
- 3 \leq N \leq 100
- S は
A,B,Cからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の中で ABC が部分文字列として初めて現れる位置を出力せよ。ただし、ABC が S に現れない場合は -1 を出力せよ。
入力例 1
8 ABABCABC
出力例 1
3
S の中で ABC が初めて現れるのは 3 文字目から 5 文字目までの位置です。よって 3 が答えになります。
入力例 2
3 ACB
出力例 2
-1
ABC が S に現れない場合は -1 を出力してください。
入力例 3
20 BBAAABBACAACABCBABAB
出力例 3
13
Score : 100 points
Problem Statement
You are given a string S of length N consisting of A, B, and C.
Find the position where ABC first appears as a (contiguous) substring in S. In other words, find the smallest integer n that satisfies all of the following conditions.
- 1 \leq n \leq N - 2.
- The string obtained by extracting the n-th through (n+2)-th characters of S is
ABC.
If ABC does not appear in S, print -1.
Constraints
- 3 \leq N \leq 100
- S is a string of length N consisting of
A,B, andC.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the position where ABC first appears as a substring in S, or -1 if it does not appear in S.
Sample Input 1
8 ABABCABC
Sample Output 1
3
ABC first appears in S at the 3-rd through 5-th characters of S. Therefore, the answer is 3.
Sample Input 2
3 ACB
Sample Output 2
-1
If ABC does not appear in S, print -1.
Sample Input 3
20 BBAAABBACAACABCBABAB
Sample Output 3
13
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
N 人が一列に並んでいます。列の状態は長さ N の文字列 S で与えられ、前から i 番目の人は S の i 文字目が M のとき男性、F のとき女性です。
男女が交互に並んでいるかどうか判定してください。
男性同士が隣り合う箇所も女性同士が隣り合う箇所も存在しないとき、かつ、そのときに限り、男女が交互に並んでいるといいます。
制約
- 1 \leq N \leq 100
- N は整数である
- S は
MおよびFのみからなる長さ N の文字列である
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
男女が交互に並んでいるとき Yes、そうでないとき No と出力せよ。
入力例 1
6 MFMFMF
出力例 1
Yes
男性同士が隣り合う箇所も女性同士が隣り合う箇所も存在せず、男女が交互に並んでいます。
入力例 2
9 FMFMMFMFM
出力例 2
No
入力例 3
1 F
出力例 3
Yes
Score : 100 points
Problem Statement
There is a row of N people. They are described by a string S of length N. The i-th person from the front is male if the i-th character of S is M, and female if it is F.
Determine whether the men and women are alternating.
It is said that the men and women are alternating if and only if there is no position where two men or two women are adjacent.
Constraints
- 1 \leq N \leq 100
- N is an integer.
- S is a string of length N consisting of
MandF.
Input
The input is given from Standard Input in the following format:
N S
Output
Print Yes if the men and women are alternating, and No otherwise.
Sample Input 1
6 MFMFMF
Sample Output 1
Yes
There is no position where two men or two women are adjacent, so the men and women are alternating.
Sample Input 2
9 FMFMMFMFM
Sample Output 2
No
Sample Input 3
1 F
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
横書きの文章が与えられます。縦書きに直してください。空白を
*で埋めてください。
N 個の、英小文字からなる文字列 S_1,S_2,\dots,S_N が与えられます。これらの文字列の長さの最大値を M とします。
以下の条件を満たす M 個の文字列 T_1,T_2,\dots,T_M を出力してください。
- 各 T_i は英小文字および
*からなる - 各 T_i の末尾は
*でない - 各 1 \leq i \leq N について、次が成り立つ
- 各 1 \leq j \leq |S_i| について、T_j の N-i+1 文字目が存在し、T_1,T_2,\dots,T_{|S_i|} それぞれの N-i+1 文字目をこの順に連結したものは S_i と一致する
- 各 |S_i| + 1 \leq j \leq M について、T_j の N-i+1 文字目は存在しないか、
*である
ただし、|S_i| で文字列 S_i の長さを表します。
制約
- N は 1 以上 100 以下の整数
- S_i は長さ 1 以上 100 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを以下の形式で出力せよ。
T_1 T_2 \vdots T_M
入力例 1
3 abc de fghi
出力例 1
fda geb h*c i
T_3 の 2 文字目を * とすることで、 c が正しい位置に来ます。
T_4 の 2,3 文字目を * とした場合、T_4 の末尾が * となり、条件を満たしません。
入力例 2
3 atcoder beginner contest
出力例 2
cba oet ngc tio end sne ter *r
Score : 200 points
Problem Statement
You are given a horizontally written text. Convert it to vertical writing, filling spaces with
*.
You are given N strings S_1, S_2, \dots, S_N consisting of lowercase English letters. Let M be the maximum length of these strings.
Print M strings T_1, T_2, \dots, T_M that satisfy the following conditions:
- Each T_i consists of lowercase English letters and
*. - Each T_i does not end with
*. - For each 1 \leq i \leq N, the following holds:
- For each 1 \leq j \leq |S_i|, the (N-i+1)-th character of T_j exists, and the concatenation of the (N-i+1)-th characters of T_1, T_2, \dots, T_{|S_i|} in this order equals S_i.
- For each |S_i| + 1 \leq j \leq M, the (N-i+1)-th character of T_j either does not exist or is
*.
Here, |S_i| denotes the length of the string S_i.
Constraints
- N is an integer between 1 and 100, inclusive.
- Each S_i is a string of lowercase English letters with length between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer in the following format:
T_1 T_2 \vdots T_M
Sample Input 1
3 abc de fghi
Sample Output 1
fda geb h*c i
Placing * as the 2nd character of T_3 puts the c in the correct position.
On the other hand, placing * as the 2nd and 3rd characters of T_4 would make T_4 end with *, which violates the condition.
Sample Input 2
3 atcoder beginner contest
Sample Output 2
cba oet ngc tio end sne ter *r
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
非負整数 A,B,C,D,E,F があり、A\times B\times C\geq D\times E\times F をみたしています。
(A\times B\times C)-(D\times E\times F) の値を 998244353 で割った余りを求めてください。
制約
- 0\leq A,B,C,D,E,F\leq 10^{18}
- A\times B\times C\geq D\times E\times F
- A,B,C,D,E,F は整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E F
出力
(A\times B\times C)-(D\times E\times F) を 998244353 で割った余りを整数で出力せよ。
入力例 1
2 3 5 1 2 4
出力例 1
22
A\times B\times C=2\times 3\times 5=30, D\times E\times F=1\times 2\times 4=8 より、
(A\times B\times C)-(D\times E\times F)=22 であり、これを 998244353 で割った余りである 22 を出力します。
入力例 2
1 1 1000000000 0 0 0
出力例 2
1755647
A\times B\times C=1000000000, D\times E\times F=0 より、
(A\times B\times C)-(D\times E\times F)=1000000000 であり、これを 998244353 で割った余りである 1755647 を出力します。
入力例 3
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
出力例 3
0
(A\times B\times C)-(D\times E\times F)=0 であり、これを 998244353 で割った余りである 0 を出力します。
Score : 200 points
Problem Statement
There are non-negative integers A, B, C, D, E, and F, which satisfy A\times B\times C\geq D\times E\times F.
Find the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353.
Constraints
- 0\leq A,B,C,D,E,F\leq 10^{18}
- A\times B\times C\geq D\times E\times F
- A, B, C, D, E, and F are integers.
Input
The input is given from Standard Input in the following format:
A B C D E F
Output
Print the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353, as an integer.
Sample Input 1
2 3 5 1 2 4
Sample Output 1
22
Since A\times B\times C=2\times 3\times 5=30 and D\times E\times F=1\times 2\times 4=8,
we have (A\times B\times C)-(D\times E\times F)=22. Divide this by 998244353 and print the remainder, which is 22.
Sample Input 2
1 1 1000000000 0 0 0
Sample Output 2
1755647
Since A\times B\times C=1000000000 and D\times E\times F=0,
we have (A\times B\times C)-(D\times E\times F)=1000000000. Divide this by 998244353 and print the remainder, which is 1755647.
Sample Input 3
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
Sample Output 3
0
We have (A\times B\times C)-(D\times E\times F)=0. Divide this by 998244353 and print the remainder, which is 0.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A = (A_1, A_2, \ldots, A_N) が与えられます。 K = 0, 1, 2, \ldots, N-1 のそれぞれについて、下記の問題を解いてください。
1 以上 N 以下の整数 i であって、次の条件を満たすものの個数を求めよ。
- A に含まれる整数のうち A_i より大きいものはちょうど K 種類である。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には K = i-1 の場合の問題の答えを出力せよ。
入力例 1
6 2 7 1 8 2 8
出力例 1
2 1 2 1 0 0
例として、K = 2 の場合の問題の答えを以下で求めます。
- A_1 = 2 に関して、A に含まれる整数のうち A_1 より大きいものは、7, 8 の 2 種類です。
- A_2 = 7 に関して、A に含まれる整数のうち A_2 より大きいものは、8 の 1 種類です。
- A_3 = 1 に関して、A に含まれる整数のうち A_3 より大きいものは、2, 7, 8 の 3 種類です。
- A_4 = 8 に関して、A に含まれる整数のうち A_4 より大きいものは、0 種類です(存在しません)。
- A_5 = 2 に関して、A に含まれる整数のうち A_5 より大きいものは、7, 8 の 2 種類です。
- A_6 = 8 に関して、A に含まれる整数のうち A_6 より大きいものは、0 種類です(存在しません)。
よって、A に含まれる整数のうちA_i より大きいものがちょうど K = 2 種類であるような i は、i = 1 と i = 5 の 2 つです。よって、K = 2 の場合の答えは 2 です。
入力例 2
1 1
出力例 2
1
入力例 3
10 979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527
出力例 3
2 1 2 1 2 1 1 0 0 0
Score : 300 points
Problem Statement
You are given a sequence A = (A_1, A_2, \ldots, A_N) of length N. For each K = 0, 1, 2, \ldots, N-1, solve the following problem.
Find the number of integers i between 1 and N (inclusive) such that:
- A contains exactly K distinct integers greater than A_i.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_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 A_2 \ldots A_N
Output
Print N lines. For i = 1, 2, \ldots, N, the i-th line should contain the answer for K = i-1.
Sample Input 1
6 2 7 1 8 2 8
Sample Output 1
2 1 2 1 0 0
For example, we will find the answer for K=2.
- Regarding A_1 = 2, A contains 2 distinct integers greater than A_1: 7 and 8.
- Regarding A_2 = 7, A contains 1 distinct integer greater than A_2: 8.
- Regarding A_3 = 1, A contains 3 distinct integers greater than A_3: 2, 7, and 8.
- Regarding A_4 = 8, A contains 0 distinct integers greater than A_4 (there is no such integer).
- Regarding A_5 = 2, A contains 2 distinct integers greater than A_5: 7 and 8.
- Regarding A_6 = 8, A contains 0 distinct integers greater than A_6 (there is no such integer).
Thus, there are two i's, i = 1 and i = 5, such that A contains exactly K = 2 distinct integers greater than A_i. Therefore, the answer for K = 2 is 2.
Sample Input 2
1 1
Sample Output 2
1
Sample Input 3
10 979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527
Sample Output 3
2 1 2 1 2 1 1 0 0 0