Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君の住む AtCoder 国には「飴を A 個以上所持している人はクッキーを B 個以上所持していなければならない」という奇妙な法律があります。
高橋君は飴を C 個、クッキーを D 個所持しています。高橋君がこの法律に違反しているかどうか判定してください。
制約
- 1\leq A,B,C,D \leq 100
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D
出力
高橋君が法律に違反しているとき Yes、違反していないとき No と出力せよ。
入力例 1
10 20 30 40
出力例 1
No
AtCoder国には「飴を 10 個以上所持している人はクッキーを 20 個以上所持していなければならない」という法律があります。
高橋君は飴を 30 個、クッキーを 40 個所持しているため、この法律に違反していません。
入力例 2
10 20 30 4
出力例 2
Yes
入力例 3
100 100 1 1
出力例 3
No
Score : 100 points
Problem Statement
In AtCoder Country where Takahashi lives, there is a strange law that "a person who possesses A or more candies must possess B or more cookies."
Takahashi possesses C candies and D cookies. Determine whether Takahashi is violating this law.
Constraints
- 1\leq A,B,C,D \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B C D
Output
Print Yes if Takahashi is violating the law, and No otherwise.
Sample Input 1
10 20 30 40
Sample Output 1
No
In AtCoder Country, there is a law that "a person who possesses 10 or more candies must possess 20 or more cookies."
Takahashi possesses 30 candies and 40 cookies, so he is not violating this law.
Sample Input 2
10 20 30 4
Sample Output 2
Yes
Sample Input 3
100 100 1 1
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
N 行 N 列からなるグリッドがあります。グリッドの上から i 行目左から j 列目のマスは、S_{i,j} が # のとき黒く、. のとき白く塗られています。
このグリッドから縦 M 行横 M 列の領域を取り出して得られるマスの塗られ方は何種類ありますか?
制約
- 1\leq M \leq N \leq 10
- N,M は整数
- S_{i,j} は
.または#
入力
入力は以下の形式で標準入力から与えられる。
N M
S_{1,1}\ldots S_{1,N}
\vdots
S_{N,1}\ldots S_{N,N}
出力
答えを出力せよ。
入力例 1
3 2 ... ### #.#
出力例 1
3
与えられたグリッドの状態は下図左のとおりです。
ここから縦 2 行横 2 列の領域を取り出す方法は下図右のとおり 4 通りあり、マスの塗られ方は 3 種類あります。

入力例 2
10 3 ..#....... .###...... .#.#...... #####..... #...#..... ......#### ......#..# ......#... ......#..# ......####
出力例 2
36
Score : 250 points
Problem Statement
There is a grid with N rows and N columns. The cell at the i-th row from the top and j-th column from the left is painted black if S_{i,j} is #, and white if it is ..
How many distinct patterns of painted cells can be obtained by extracting a region of M rows and M columns from this grid?
Constraints
- 1\leq M \leq N \leq 10
- N and M are integers.
- S_{i,j} is
.or#.
Input
The input is given from Standard Input in the following format:
N M
S_{1,1}\ldots S_{1,N}
\vdots
S_{N,1}\ldots S_{N,N}
Output
Print the answer.
Sample Input 1
3 2 ... ### #.#
Sample Output 1
3
The state of the given grid is as shown in the left figure below.
There are four ways to extract a region of two rows and two columns from this grid as shown in the right figure below, and there are three distinct patterns of painted cells.

Sample Input 2
10 3 ..#....... .###...... .#.#...... #####..... #...#..... ......#### ......#..# ......#... ......#..# ......####
Sample Output 2
36
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder 国には「トラック運転手は A 分以上運転する際には B 分以上の休憩を取らなければならない」というルールがあります。
a, b からなる長さ N の文字列 S と正整数 A,B が与えられます。以下の条件を全て満たす整数組 (l,r) の個数を求めてください。
- 1\leq l \leq r \leq N
- S の l 文字目から r 文字目までに含まれる
aの個数が A 以上 - S の l 文字目から r 文字目までに含まれる
bの個数が B 未満
制約
- 1\leq N \leq 3\times 10^5
- 1 \leq A,B \leq N
- S は
a,bのみからなる長さ N の文字列 - 与えられる数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A B S
出力
答えを出力せよ。
入力例 1
11 4 2 abbaaabaaba
出力例 1
3
条件を満たす (l,r) の組は (4,8),(4,9),(5,9) の 3 個です。
入力例 2
13 1 2 bbbbbbbbbbbbb
出力例 2
0
条件を満たす (l,r) の組は存在しません。
Score : 300 points
Problem Statement
In AtCoder Country, there is a rule that "a truck driver must take a break of at least B minutes when driving for A minutes or more."
You are given a string S of length N consisting of a and b, and positive integers A and B. Find the number of integer pairs (l,r) that satisfy all of the following conditions.
- 1\leq l \leq r \leq N
- The number of
ain the substring from the l-th character through the r-th character of S is greater than or equal to A. - The number of
bin the substring from the l-th character through the r-th character of S is less than B.
Constraints
- 1\leq N \leq 3\times 10^5
- 1 \leq A,B \leq N
- S is a string of length N consisting of
aandb. - All input numbers are integers.
Input
The input is given from Standard Input in the following format:
N A B S
Output
Print the answer.
Sample Input 1
11 4 2 abbaaabaaba
Sample Output 1
3
The pairs (l,r) that satisfy the conditions are (4,8),(4,9),(5,9), which is three pairs.
Sample Input 2
13 1 2 bbbbbbbbbbbbb
Sample Output 2
0
There are no pairs (l,r) that satisfy the conditions.
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
数直線があり、最初は座標 0 に人 0 がひとりで立っています。
これから、人 1,2,\dots,N がこの順に到着し、数直線上に立ちます。
人 i は座標 X_i に立ちます。なお、 X_i \ge 1 であり、全ての人について X_i は相異なります。
人が到着するたびに、以下の問いに答えてください。
- 現在数直線に人 0,1,\dots,r の r+1 人が立っているとする。
- このとき、 d_i を「人 i に最も近い別の人までの距離」と定義する。
- より厳密には、 \displaystyle d_i = \min_{0 \le j \le r, j \neq i} \vert X_i - X_j \vert とする。
- この d の総和、すなわち \displaystyle \sum_{i=0}^r d_i を求めよ。
制約
- 入力は全て整数
- 1 \le N \le 5 \times 10^5
- 1 \le X_i \le 10^9
- i \neq j ならば X_i \neq X_j
入力
入力は以下の形式で標準入力から与えられる。
N X_1 X_2 \dots X_N
出力
N 行に出力せよ。
そのうち i ( 1 \le i \le N ) 行目には、人 i が到着した時点での問いの答えを出力せよ。
入力例 1
10 5 2 7 4 108728325 390529120 597713292 322456626 845148281 812604915
出力例 1
10 7 8 8 108728326 390529121 523096670 452057486 699492475 517144218
この入力では、人が 10 人到着します。
このうち最初の 4 人について説明します。
- 人 1 が到着した時点で、座標 0,5 に人がいます。
- 求める値は 5+5=10 です。
- 人 2 が到着した時点で、座標 0,2,5 に人がいます。
- 求める値は 2+2+3=7 です。
- 人 3 が到着した時点で、座標 0,2,5,7 に人がいます。
- 求める値は 2+2+2+2=8 です。
- 人 4 が到着した時点で、座標 0,2,4,5,7 に人がいます。
- 求める値は 2+2+1+1+2=8 です。
Score : 400 points
Problem Statement
There is a number line, and initially person 0 is standing alone at coordinate 0.
From now on, persons 1,2,\dots,N will arrive in this order and stand on the number line.
Person i stands at coordinate X_i. Here, X_i \ge 1, and X_i is distinct for all persons.
Each time a person arrives, answer the following question.
- Suppose that currently r+1 persons 0,1,\dots,r are standing on the number line.
- Here, define d_i as the distance to the nearest other person from person i.
- More formally, \displaystyle d_i = \min_{0 \le j \le r, j \neq i} \vert X_i - X_j \vert.
- Find the sum of this d, that is, \displaystyle \sum_{i=0}^r d_i.
Constraints
- All input values are integers.
- 1 \le N \le 5 \times 10^5
- 1 \le X_i \le 10^9
- X_i \neq X_j if i \neq j.
Input
The input is given from Standard Input in the following format:
N X_1 X_2 \dots X_N
Output
Print N lines.
The i-th line ( 1 \le i \le N ) should contain the answer to the question when person i arrives.
Sample Input 1
10 5 2 7 4 108728325 390529120 597713292 322456626 845148281 812604915
Sample Output 1
10 7 8 8 108728326 390529121 523096670 452057486 699492475 517144218
In this input, 10 persons arrive.
The first four persons are explained below.
- When person 1 arrives, there are persons at coordinates 0,5.
- The required value is 5+5=10.
- When person 2 arrives, there are persons at coordinates 0,2,5.
- The required value is 2+2+3=7.
- When person 3 arrives, there are persons at coordinates 0,2,5,7.
- The required value is 2+2+2+2=8.
- When person 4 arrives, there are persons at coordinates 0,2,4,5,7.
- The required value is 2+2+1+1+2=8.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
0, 1 からなる長さの等しい文字列 A,B が与えられます。
A に対して以下の操作を 0 回以上何度でも行うことができます。
- A の先頭の文字を末尾に移動させる。
A=B とするために必要な最小の操作回数を求めてください。
但し、どのように操作しても A=B とできない場合、代わりに -1 と出力してください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1 \le T \le 10000
- A,B は
0,1からなる文字列 - 2 \le |A|=|B| \le 10^6
- ひとつの入力について、 |A| の総和は 10^6 を超えない
入力
入力は以下の形式で標準入力から与えられる。
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
各テストケースは以下の形式で与えられる。
A B
出力
T 行出力せよ。
i 行目には i 番目のテストケースについて、答えを出力せよ。
入力例 1
5 1010001 1000110 000 111 01010 01010 0101 0011 100001101110000001010110110001 101100011000011011100000010101
出力例 1
2 -1 0 -1 22
この入力には 5 個のテストケースが含まれます。
- 1 番目のテストケースについて、 A=
1010001、 B=1000110です。- A に操作を 2 回行うと A が
1010001\rightarrow0100011\rightarrow1000110となり、 A=B とできます。
- A に操作を 2 回行うと A が
- 2 番目のテストケースについて、どのように操作を行っても
000を111にすることはできません。 - 3 番目のテストケースについて、はじめから A=B です。
Score : 450 points
Problem Statement
You are given strings A and B of equal length consisting of 0 and 1.
You can perform the following operation on A zero or more times.
- Move the first character of A to the end.
Find the minimum number of operations required to make A=B.
If it is impossible to make A=B no matter how you operate, print -1 instead.
You are given T test cases; find the answer for each of them.
Constraints
- 1 \le T \le 10000
- A and B are strings consisting of
0and1. - 2 \le |A|=|B| \le 10^6
- For a single input, the sum of |A| does not exceed 10^6.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
Each test case is given in the following format:
A B
Output
Print T lines.
The i-th line should contain the answer for the i-th test case.
Sample Input 1
5 1010001 1000110 000 111 01010 01010 0101 0011 100001101110000001010110110001 101100011000011011100000010101
Sample Output 1
2 -1 0 -1 22
This input contains five test cases.
- For the first test case, A=
1010001and B=1000110.- By performing the operation on A twice, A becomes
1010001\rightarrow0100011\rightarrow1000110, which makes A=B.
- By performing the operation on A twice, A becomes
- For the second test case, no matter how you perform the operation, you cannot change
000to111. - For the third test case, A=B from the beginning.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
整数 N と長さ N-1 の L, R からなる文字列 S が与えられます。
横一列に並んだ N 個のマス目に、以下の条件を全て満たすように整数を書き込むことを考えます。
- 全てのマスに整数が 1 つ書かれている。
- 整数 1,2,\dots,N が書かれているマスが 1 つずつ存在する。
- S の i 文字目 が
Lであるとき、 i+1 は i より左に書き込まれている。 - S の i 文字目 が
Rであるとき、 i+1 は i より右に書き込まれている。
C_i を「左から i マス目に書き込まれる整数としてありうるものの個数」とします。 C_1,C_2,\dots,C_N を求めてください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1 \le T \le 20000
- 2 \le N \le 3 \times 10^5
- S は長さ N-1 の
L,Rからなる文字列 - ひとつの入力について、 N の総和は 3 \times 10^5 を超えない
入力
入力は以下の形式で標準入力から与えられる。
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
各テストケースは以下の形式で与えられる。
N S
出力
T 行出力せよ。
i 行目には i 番目のテストケースについて、答えを以下の形式で出力せよ。
C_1 C_2 \dots C_N
入力例 1
5 5 RLLR 3 RL 2 L 3 RR 20 RLLLLLLLLRLRRLLLRLR
出力例 1
2 4 3 4 2 2 2 1 1 1 1 1 1 5 9 13 14 15 17 18 19 19 20 20 19 19 18 17 16 14 12 9 5
この入力には 5 個のテストケースが含まれます。
- 1 番目のテストケースにおいて、マス目の埋め方として考えられるものは以下の 11 個です。
- (1,4,3,2,5)
- (1,4,3,5,2)
- (1,4,5,3,2)
- (4,1,3,2,5)
- (4,1,3,5,2)
- (4,1,5,3,2)
- (4,3,1,2,5)
- (4,3,1,5,2)
- (4,3,5,1,2)
- (4,5,1,3,2)
- (4,5,3,1,2)
- ここから、 C_i の各値は次の通りに求まります。
- 左から 1 マス目に書き込まれる整数としてありうるものは 1,4 の 2 個です。
- 左から 2 マス目に書き込まれる整数としてありうるものは 1,3,4,5 の 4 個です。
- 左から 3 マス目に書き込まれる整数としてありうるものは 1,3,5 の 3 個です。
- 左から 4 マス目に書き込まれる整数としてありうるものは 1,2,3,5 の 4 個です。
- 左から 5 マス目に書き込まれる整数としてありうるものは 2,5 の 2 個です。
- 2 番目のテストケースにおいて、マス目の埋め方として考えられるものは以下の 2 通りです。
- (1,3,2)
- (3,1,2)
- 3 番目のテストケースにおいて、マス目の埋め方として考えられるものは以下の 1 通りです。
- (2,1)
- 4 番目のテストケースにおいて、マス目の埋め方として考えられるものは以下の 1 通りです。
- (1,2,3)
Score : 500 points
Problem Statement
You are given an integer N and a string S of length N-1 consisting of L and R.
Consider writing integers into N cells arranged in a row so that the following conditions are satisfied:
- Every cell has one integer written on it.
- Every integer 1,2,\dots,N appears in exactly one cell.
- When the i-th character of S is
L, i+1 is written to the left of i. - When the i-th character of S is
R, i+1 is written to the right of i.
Let C_i be the number of integers that can be written in the i-th cell from the left. Find C_1,C_2,\dots,C_N.
You are given T test cases; find the answer for each of them.
Constraints
- 1 \le T \le 20000
- 2 \le N \le 3 \times 10^5
- S is a string of length N-1 consisting of
LandR. - For a single input, the sum of N does not exceed 3 \times 10^5.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
Each test case is given in the following format:
N S
Output
Print T lines.
The i-th line should contain the answer for the i-th test case in the following format:
C_1 C_2 \dots C_N
Sample Input 1
5 5 RLLR 3 RL 2 L 3 RR 20 RLLLLLLLLRLRRLLLRLR
Sample Output 1
2 4 3 4 2 2 2 1 1 1 1 1 1 5 9 13 14 15 17 18 19 19 20 20 19 19 18 17 16 14 12 9 5
This input contains five test cases.
- For the first test case, there are 11 possible ways to fill the cells as follows:
- (1,4,3,2,5)
- (1,4,3,5,2)
- (1,4,5,3,2)
- (4,1,3,2,5)
- (4,1,3,5,2)
- (4,1,5,3,2)
- (4,3,1,2,5)
- (4,3,1,5,2)
- (4,3,5,1,2)
- (4,5,1,3,2)
- (4,5,3,1,2)
- From this, each value of C_i is determined as follows:
- The integers that can be written in the 1-st cell from the left are 1,4, which is two integers.
- The integers that can be written in the 2-nd cell from the left are 1,3,4,5, which is four integers.
- The integers that can be written in the 3-rd cell from the left are 1,3,5, which is three integers.
- The integers that can be written in the 4-th cell from the left are 1,2,3,5, which is four integers.
- The integers that can be written in the 5-th cell from the left are 2,5, which is two integers.
- For the second test case, there are two possible ways to fill the cells as follows:
- (1,3,2)
- (3,1,2)
- For the third test case, there is one possible way to fill the cells as follows:
- (2,1)
- For the fourth test case, there is one possible way to fill the cells as follows:
- (1,2,3)
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 625 点
問題文
N 個の集合 S_1, \ldots,S_N があります。最初、全ての集合は空集合です。
以下の形式のクエリが Q 個与えられるので順に処理してください。
- タイプ 1:
1 L R xの形式で与えられる。L \leq i \leq R を満たす各 S_i に対し、x を追加する。 - タイプ 2:
2 L R xの形式で与えられる。L \leq i \leq R を満たす各 S_i に対し、x を削除する。 - タイプ 3:
3 L Rの形式で与えられる。L \leq i \leq R を満たす S_i のうちの、要素数の最大値と、それを達成する集合の個数を求める。
制約
- 1\leq N \leq 3\times 10^5
- 1\leq Q \leq 3\times 10^5
- 各クエリにおいて、1 \leq L \leq R \leq N
- タイプ 1,2 のクエリにおいて、1 \leq x \leq 60
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
ただし、\mathrm{query}_i は i 番目のクエリを表し、それぞれ問題文中に示した以下の形式で与えられる。
1 L R x
2 L R x
3 L R
出力
タイプ 3 のクエリの個数を q として q 行出力せよ。
i 行目には、i 個目のタイプ 3 のクエリにおいて、要素数の最大値を x、それを達成する集合の個数を y として、x,y を空白区切りで出力せよ。
入力例 1
4 7 1 1 2 10 1 2 4 20 3 1 3 2 1 2 20 1 2 3 10 3 1 2 3 1 4
出力例 1
2 1 1 2 2 1
- 最初 (S_1,S_2,S_3,S_4)=(\lbrace\rbrace,\lbrace\rbrace,\lbrace\rbrace,\lbrace\rbrace) です。
- 1 番目のクエリにより S_1,S_2 に 10 が追加され、(S_1,S_2,S_3,S_4)=(\lbrace 10\rbrace,\lbrace 10\rbrace,\lbrace\rbrace,\lbrace\rbrace) となります。
- 2 番目のクエリにより S_2,S_3,S_4 に 20 が追加され、(S_1,S_2,S_3,S_4)=(\lbrace 10\rbrace,\lbrace 10,20\rbrace,\lbrace 20\rbrace,\lbrace 20\rbrace) となります。
- 3 番目のクエリにおいて、S_1,S_2,S_3 のうち要素数が最大となるのは S_2 の 2 個であるため、
2 1を出力します。 - 4 番目のクエリにより S_1,S_2 から 20 が削除され、(S_1,S_2,S_3,S_4)=(\lbrace 10\rbrace,\lbrace 10\rbrace,\lbrace 20\rbrace,\lbrace 20\rbrace) となります。
- 5 番目のクエリにより S_2,S_3 に 10 が追加され、(S_1,S_2,S_3,S_4)=(\lbrace 10\rbrace,\lbrace 10\rbrace,\lbrace 10,20\rbrace,\lbrace 20\rbrace) となります。
- 6 番目のクエリにおいて、S_1,S_2 のうち要素数が最大となるのは S_1,S_2 の 1 個であるため、
1 2を出力します。 - 7 番目のクエリにおいて、S_1,S_2,S_3,S_4 のうち要素数が最大となるのは S_3 の 2 個であるため、
2 1を出力します。
Score : 625 points
Problem Statement
There are N sets S_1, \ldots,S_N. Initially, all sets are empty.
You are given Q queries in the following formats. Process them in order.
- Type 1: Given as
1 L R x. For each S_i satisfying L \leq i \leq R, add x. - Type 2: Given as
2 L R x. For each S_i satisfying L \leq i \leq R, remove x. - Type 3: Given as
3 L R. Find the maximum number of elements among S_i satisfying L \leq i \leq R, and the number of sets that achieve this maximum.
Constraints
- 1\leq N \leq 3\times 10^5
- 1\leq Q \leq 3\times 10^5
- For each query, 1 \leq L \leq R \leq N.
- For type 1,2 queries, 1 \leq x \leq 60.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
Here, \mathrm{query}_i represents the i-th query, and each is given in one of the following formats as shown in the problem statement:
1 L R x
2 L R x
3 L R
Output
Let q be the number of type 3 queries, and print q lines.
The i-th line should contain x,y separated by a space, where x is the maximum number of elements and y is the number of sets that achieve this maximum for the i-th type 3 query.
Sample Input 1
4 7 1 1 2 10 1 2 4 20 3 1 3 2 1 2 20 1 2 3 10 3 1 2 3 1 4
Sample Output 1
2 1 1 2 2 1
- Initially (S_1,S_2,S_3,S_4)=(\lbrace\rbrace,\lbrace\rbrace,\lbrace\rbrace,\lbrace\rbrace).
- The 1-st query adds 10 to S_1,S_2, resulting in (S_1,S_2,S_3,S_4)=(\lbrace 10\rbrace,\lbrace 10\rbrace,\lbrace\rbrace,\lbrace\rbrace).
- The 2-nd query adds 20 to S_2,S_3,S_4, resulting in (S_1,S_2,S_3,S_4)=(\lbrace 10\rbrace,\lbrace 10,20\rbrace,\lbrace 20\rbrace,\lbrace 20\rbrace).
- For the 3-rd query, the maximum number of elements among S_1,S_2,S_3 is 2 achieved by S_2, so print
2 1. - The 4-th query removes 20 from S_1,S_2, resulting in (S_1,S_2,S_3,S_4)=(\lbrace 10\rbrace,\lbrace 10\rbrace,\lbrace 20\rbrace,\lbrace 20\rbrace).
- The 5-th query adds 10 to S_2,S_3, resulting in (S_1,S_2,S_3,S_4)=(\lbrace 10\rbrace,\lbrace 10\rbrace,\lbrace 10,20\rbrace,\lbrace 20\rbrace).
- For the 6-th query, the maximum number of elements among S_1,S_2 is 1 achieved by S_1,S_2, so print
1 2. - For the 7-th query, the maximum number of elements among S_1,S_2,S_3,S_4 is 2 achieved by S_3, so print
2 1.