実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
10^{100} 行 10^{100} 列のマス目があります。
以下では、上から i 行目かつ左から j 列目のマスをマス (i,j) と表します。
マス目のうち、マス (P,Q) を一番左上のマスとした 100\times 100 マスの領域のみが黒く塗られており、それ以外のマスは白く塗られています。
マス (X,Y) が黒く塗られているか判定してください。
制約
- 1 \leq P,Q,X,Y \leq 10000
- P,Q,X,Y は整数
入力
入力は以下の形式で標準入力から与えられる。
P Q X Y
出力
マス (X,Y) が黒く塗られているならば Yes を、そうでないならば No を出力せよ。
入力例 1
3 3 5 10
出力例 1
Yes
マス (3,3) を最も左上のマスとする 100\times 100 マスの領域が黒く塗られています。
マス (5,10) はこの領域に含まれているため、Yes を出力します。
入力例 2
5 5 10 1000
出力例 2
No
マス (5,5) を最も左上のマスとする 100\times 100 マスの領域が黒く塗られています。
マス (10,1000) はこの領域に含まれていないため、No を出力します。
入力例 3
1 2 1 1
出力例 3
No
マス (1,2) を最も左上のマスとする 100\times 100 マスの領域が黒く塗られています。
マス (1,1) はこの領域に含まれていないため、No を出力します。
Score : 100 points
Problem Statement
There is a grid with 10^{100} rows and 10^{100} columns.
In what follows, the cell at the i-th row from the top and j-th column from the left is denoted as cell (i,j).
In this grid, only the 100\times 100 region with cell (P,Q) as the top-left cell is painted black, and all other cells are painted white.
Determine whether cell (X,Y) is painted black.
Constraints
- 1 \leq P,Q,X,Y \leq 10000
- P,Q,X,Y are integers.
Input
The input is given from Standard Input in the following format:
P Q X Y
Output
If cell (X,Y) is painted black, print Yes; otherwise, print No.
Sample Input 1
3 3 5 10
Sample Output 1
Yes
The 100\times 100 region with cell (3,3) as the top-left cell is painted black.
Cell (5,10) is included in this region, so print Yes.
Sample Input 2
5 5 10 1000
Sample Output 2
No
The 100\times 100 region with cell (5,5) as the top-left cell is painted black.
Cell (10,1000) is not included in this region, so print No.
Sample Input 3
1 2 1 1
Sample Output 3
No
The 100\times 100 region with cell (1,2) as the top-left cell is painted black.
Cell (1,1) is not included in this region, so print No.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
AtCoder 国の公用語は、高橋語と青木語の 2 つの言語です。
高橋語と青木語は、どちらもその言語に含まれる単語を表記するのに英小文字の一部を使います。 高橋語では長さ N の文字列 S に含まれる文字のみを使い、青木語では長さ M の文字列 T に含まれる文字のみを使います。
AtCoder 国の公用語に含まれる Q 個の単語 w _ 1,w _ 2,\ldots,w _ Q が与えられます。 それぞれの単語について、その単語に含まれる文字からその単語が次のうちどれに該当するか判定してください。
- 高橋語の単語であることが確定する
- 青木語の単語であることが確定する
- どちらともいえない
制約
- 1\le N\le26
- 1\le M\le26
- S は英小文字からなる長さ N の文字列
- S に含まれる文字は先頭からアルファベット順で昇順に並んでいる
- S に含まれる文字はすべて異なる
- T は英小文字からなる長さ M の文字列
- T に含まれる文字は先頭からアルファベット順で昇順に並んでいる
- T に含まれる文字はすべて異なる
- 1\le Q\le100
- w _ i は英小文字からなる長さ 1 以上 100 以下の文字列 (1\le i\le Q)
- w _ i は高橋語か青木語のどちらかの単語 (1\le i\le Q)
- N,M,Q は整数
入力
入力は以下の形式で標準入力から与えられる。
N M S T Q w _ 1 w _ 2 \vdots w _ Q
出力
Q 行にわたって出力せよ。
i 行目には、w _ i が高橋語の単語であることが確定するなら Takahashi 、青木語の単語であることが確定するなら Aoki 、どちらとも確定しないなら Unknown と出力せよ。
入力例 1
6 5 ahikst aikot 5 asahi okita kiai hash it
出力例 1
Takahashi Aoki Unknown Takahashi Unknown
例えば、a, s, h, i はすべて高橋語で使われる文字で、h は青木語で使われる文字ではないので asahi は高橋語の単語であることが確定します。
よって、1 行目には Takahashi と出力してください。
i および t はどちらも高橋語でも青木語でも使われる文字なので it は高橋語の単語であるとも青木語の単語であるとも確定しません。
よって、5 行目には Unknown と出力してください。
入力例 2
7 6 ahiknst ahikos 5 kioki ohiki tashi nishi kashi
出力例 2
Aoki Aoki Takahashi Takahashi Unknown
o は高橋語で使われる文字ではないので、はじめ 2 つの単語は青木語の単語であることが確定します。
よって、1 行目と 2 行目には Aoki と出力してください。
t や n は青木語で使われる文字ではないので、続く 2 つの単語は高橋語の単語であることが確定します。
よって、3 行目と 4 行目には Takahashi と出力してください。
はじめ 4 つの単語については、末尾が shi なら高橋語、末尾が ki なら青木語という法則がありますが、k, a, s, h, i はいずれも高橋語と青木語の両方で使われる文字なので kashi がどちらの言語の単語であるかを使われている文字から確定させることはできません。
よって、5 行目には Unknown と出力してください。
入力例 3
13 11 defghiqsvwxyz acejmoqrtwx 15 qhsqzhd jcareec wwqxqew wxqxwex jxxrtwa trtqjxe sqyggse xxqwxew xewwxxw wwqxwex xqqxqwq qxxexxe teqeroc eeeqqee vxdevyy
出力例 3
Takahashi Aoki Unknown Unknown Aoki Aoki Takahashi Unknown Unknown Unknown Unknown Unknown Aoki Unknown Takahashi
Score : 200 points
Problem Statement
The AtCoder country has two official languages: Takahashi-go and Aoki-go.
Both Takahashi-go and Aoki-go use some lowercase English letters to write words in those languages. Takahashi-go uses only the characters contained in a string S of length N, and Aoki-go uses only the characters contained in a string T of length M.
You are given Q words w _ 1,w _ 2,\ldots,w _ Q that are in the official languages of the AtCoder country. For each word, determine which of the following applies based on the characters contained in that word:
- It is confirmed to be a word in Takahashi-go
- It is confirmed to be a word in Aoki-go
- Neither can be determined
Constraints
- 1\le N\le26
- 1\le M\le26
- S is a string of length N consisting of lowercase English letters.
- The characters in S are arranged in alphabetical order.
- All characters in S are distinct.
- T is a string of length M consisting of lowercase English letters.
- The characters in T are arranged in alphabetical order.
- All characters in T are distinct.
- 1\le Q\le100
- w _ i is a string of length at least 1 and at most 100 consisting of lowercase English letters. (1\le i\le Q)
- w _ i is a word in Takahashi-go or Aoki-go. (1\le i\le Q)
- N,M,Q are integers.
Input
The input is given from Standard Input in the following format:
N M S T Q w _ 1 w _ 2 \vdots w _ Q
Output
Print Q lines.
The i-th line should contain Takahashi if it is confirmed that w _ i is a word in Takahashi-go, Aoki if it is confirmed to be a word in Aoki-go, and Unknown if neither can be determined.
Sample Input 1
6 5 ahikst aikot 5 asahi okita kiai hash it
Sample Output 1
Takahashi Aoki Unknown Takahashi Unknown
For example, all of a, s, h, i are used in Takahashi-go, and h is not used in Aoki-go, so it is confirmed that asahi is a word in Takahashi-go.
Thus, print Takahashi on the first line.
Both i and t are used in both Takahashi-go and Aoki-go, so it cannot be determined whether it is a word in Takahashi-go or Aoki-go.
Thus, print Unknown on the fifth line.
Sample Input 2
7 6 ahiknst ahikos 5 kioki ohiki tashi nishi kashi
Sample Output 2
Aoki Aoki Takahashi Takahashi Unknown
o is not used in Takahashi-go, so the first two words are confirmed to be words in Aoki-go.
Thus, print Aoki on the first and second lines.
t and n are not used in Aoki-go, so the following two words are confirmed to be words in Takahashi-go.
Thus, print Takahashi on the third and fourth lines.
For the first four words, there is a rule that words ending in shi are Takahashi-go, and words ending in ki are Aoki-go. However, all of k, a, s, h, i are used in both Takahashi-go and Aoki-go, so it is impossible to determine which language the word kashi belongs to based on the characters used.
Thus, print Unknown on the fifth line.
Sample Input 3
13 11 defghiqsvwxyz acejmoqrtwx 15 qhsqzhd jcareec wwqxqew wxqxwex jxxrtwa trtqjxe sqyggse xxqwxew xewwxxw wwqxwex xqqxqwq qxxexxe teqeroc eeeqqee vxdevyy
Sample Output 3
Takahashi Aoki Unknown Unknown Aoki Aoki Takahashi Unknown Unknown Unknown Unknown Unknown Aoki Unknown Takahashi
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
N 個のカップがあり、それぞれのカップには無色透明な液体が入っています。
具体的には、i 番目 (1\leq i\leq N) のカップには A_i ml の液体が入っています。
また、これらのうちちょうど K 個のカップには日本酒が入っており、それ以外には水が入っていることが分かっています。
ただし、どのカップに日本酒が入っているかについては分かっていません。
高橋君は(1 つ以上の)いくつかのカップを選んでそれらに入った液体をすべて飲むことができます。
どのカップに日本酒が入っているかによらず、高橋君が確実に X ml 以上の日本酒を飲むためには、最低何個のカップを選ぶ必要があるか求めてください。
そのような選び方が不可能である場合には -1 を出力してください。
制約
- 1 \leq K \leq N \leq 3\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq X \leq 3\times 10^{14}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K X A_1 A_2 \ldots A_N
出力
条件をみたすために高橋君が選ぶ必要があるカップの個数の最小値を出力せよ。 そのような選び方が不可能である場合には -1 を出力せよ。
入力例 1
3 2 5 10 6 8
出力例 1
2
高橋君が 1 番目と 3 番目のカップを選んで飲んだ場合を考えます。
3 個のカップのうち 2 個に日本酒が入っているため、次の 3 通りが考えられます。
- 1,2 番目のカップに日本酒が入っていた場合
高橋君は 10 ml の日本酒と 8 ml の水を飲むことになります。
- 1,3 番目のカップに日本酒が入っていた場合
高橋君は 18 ml の日本酒を飲むことになります。
- 2,3 番目のカップに日本酒が入っていた場合
高橋君は 8 ml の日本酒と 10 ml の水を飲むことになります。
よって、いずれの場合でも 5 ml 以上の日本酒を飲むことができます。
一方で、どのカップに日本酒が入っているか分かっていない状態で、1 つのみのカップを選んで条件をみたすようにすることは不可能です。
よって、2 を出力します。
入力例 2
2 1 8 6 10
出力例 2
-1
1 番目のカップに日本酒が入っていた場合、どのようにカップを選んでも 8 ml 以上の日本酒を飲むことは不可能です。
よって、-1 を出力します。
入力例 3
5 3 3000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 3
5
Score : 300 points
Problem Statement
There are N cups, each containing a colorless and transparent liquid.
Specifically, the i-th (1\leq i\leq N) cup contains A_i ml of liquid.
It is known that exactly K of these cups contain sake (rice wine), and the rest contain water.
However, it is not known which cups contain sake.
Takahashi can choose some (one or more) cups and drink all the liquid in them.
Find the minimum number of cups he needs to choose to ensure he drinks at least X ml of sake, regardless of which cups contain sake.
If such a choice is impossible, print -1.
Constraints
- 1 \leq K \leq N \leq 3\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq X \leq 3\times 10^{14}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K X A_1 A_2 \ldots A_N
Output
Print the minimum number of cups Takahashi needs to choose to satisfy the condition. If such a choice is impossible, print -1.
Sample Input 1
3 2 5 10 6 8
Sample Output 1
2
Consider the case where Takahashi chooses the first and third cups and drinks them.
Two out of the three cups contain sake, so the following three cases are possible:
- If the first and second cups contain sake
He drinks 10 ml of sake and 8 ml of water.
- If the first and third cups contain sake
He drinks 18 ml of sake.
- If the second and third cups contain sake
He drinks 8 ml of sake and 10 ml of water.
Thus, in all cases, he can drink at least 5 ml of sake.
On the other hand, it is impossible to satisfy the condition by choosing only one cup without knowing which cups contain sake.
Therefore, print 2.
Sample Input 2
2 1 8 6 10
Sample Output 2
-1
If the first cup contained sake, it is impossible to drink 8 ml or more of sake no matter which cups are chosen.
Therefore, print -1.
Sample Input 3
5 3 3000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 3
5
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N 頂点 M 辺の(単純とは限らない)有向グラフがあり、頂点は頂点 1, 2, \ldots, N と番号付けられています。
i 番目 (1\leq i\leq M) の辺は頂点 U_i から頂点 V_i へ向かう辺で、コストは C_i です。
また、各頂点の出次数は 4 以下です。
次の条件をみたす頂点 v (1\leq v\leq N) をすべて求めてください。
頂点 1 から頂点 v への経路であって、次の条件をともにみたすものが存在する。
- ちょうど L 回辺を通る。このとき、同じ辺を複数回通っても良いが、通るたびに回数にカウントされる。
- 通った辺のコストの総和が S 以上 T 以下である。(同じ辺を複数回通った場合、通るたびに総和に加算されるものとする。)
出次数 とは
頂点 u の出次数は、頂点 u から出て行く辺の数を指します。辺の向かう先が同じ頂点であるような辺であっても重ねて数えられます。制約
- 1\leq N\leq 2\times 10^5
- 1\leq M\leq 2\times 10^5
- 1\leq L \leq 10
- 1\leq S\leq T \leq 10^9
- 1\leq U_i,V_i\leq N
- 1\leq C_i\leq 10^8
- 各頂点の出次数は高々 4 である。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M L S T U_1 V_1 C_1 U_2 V_2 C_2 \vdots U_M V_M C_M
出力
条件をみたす頂点を 昇順に 空白区切りで出力せよ。
条件をみたす頂点が存在しない場合は空行を出力せよ。
入力例 1
5 8 3 80 100 1 2 20 1 3 70 2 1 30 2 5 10 3 2 10 3 4 30 3 5 20 5 1 70
出力例 1
1 5
与えられるグラフは下図左のようになっています。各辺のコストはその辺の始点のそばに示されています。

このとき、以下のようになります。
- 頂点 1 から頂点 1 への経路について、頂点 1 \to 頂点 2 \to 頂点 5 \to 頂点 1 (上図中央)を考えると、これはちょうど 3 本の辺を通り、通る辺のコストの総和は 20+10+70=100 であるため、条件をみたしています。
- 頂点 1 から頂点 2 への経路であって、条件をみたすような経路は存在しません。ちょうど 3 本の辺を通るような経路としては、頂点 1 \to 頂点 2 \to 頂点 1 \to 頂点 2 が存在しますが、この経路において通る辺のコストの総和は 20+30+20=70 であり特に 80 より小さいため、条件をみたしていません。
- 頂点 1 から頂点 3 への経路であって、条件をみたすような経路は存在しません。ちょうど 3 本の辺を通るような経路としては、頂点 1 \to 頂点 2 \to 頂点 1 \to 頂点 3 が存在しますが、この経路において通る辺のコストの総和は 20+30+70=120 であり特に 100 より大きいため、条件をみたしていません。
- 頂点 1 から頂点 4 への経路であって、条件をみたすような経路は存在しません。
- 頂点 1 から頂点 5 への経路について、頂点 1 \to 頂点 3 \to 頂点 2 \to 頂点 5 (上図右)を考えると、これはちょうど 3 本の辺を通り、通る辺のコストの総和は 70+10+10=90 であるため、条件をみたしています。
よって、1, 5 をこの順に出力します。条件をみたす頂点を昇順に出力する必要があることに注意してください。
入力例 2
10 1 1 1 100 2 3 1
出力例 2
条件をみたす頂点が存在しない場合は空行を出力してください。
入力例 3
2 5 3 1 100 1 1 1 2 2 100 1 2 1 1 2 1 1 2 100
出力例 3
1 2
グラフは自己ループや多重辺を含む可能性があります。
なお、このテストケースにおけるグラフの頂点 1,2 からの出次数はそれぞれ 4,1 です。
Score : 400 points
Problem Statement
There is a directed graph (not necessarily simple) with N vertices and M edges, where the vertices are numbered as vertices 1, 2, \ldots, N.
The i-th (1\leq i\leq M) edge goes from vertex U_i to vertex V_i with cost C_i.
Additionally, the out-degree of each vertex is at most 4.
Find all vertices v (1\leq v\leq N) that satisfy the following condition:
There exists a path from vertex 1 to vertex v that satisfies both of the following conditions:
- It traverses exactly L edges. If the same edge is traversed multiple times, each traversal is counted.
- The sum of the costs of the traversed edges is at least S and at most T. (If the same edge is traversed multiple times, the cost is added to the sum each time.)
What is out-degree?
The out-degree of vertex u refers to the number of edges going out from vertex u. Even if multiple edges go to the same vertex, they are counted separately.Constraints
- 1\leq N\leq 2\times 10^5
- 1\leq M\leq 2\times 10^5
- 1\leq L \leq 10
- 1\leq S\leq T \leq 10^9
- 1\leq U_i,V_i\leq N
- 1\leq C_i\leq 10^8
- The out-degree of each vertex is at most 4.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M L S T U_1 V_1 C_1 U_2 V_2 C_2 \vdots U_M V_M C_M
Output
Print the vertices that satisfy the condition in ascending order, separated by spaces.
If there are no vertices that satisfy the condition, print an empty line.
Sample Input 1
5 8 3 80 100 1 2 20 1 3 70 2 1 30 2 5 10 3 2 10 3 4 30 3 5 20 5 1 70
Sample Output 1
1 5
The given graph is as shown in the left figure below. The cost of each edge is shown near the starting vertex of that edge.

Here, the following holds:
- For the path from vertex 1 to vertex 1, consider vertex 1 \to vertex 2 \to vertex 5 \to vertex 1 (center of the figure above). This traverses exactly three edges, and the sum of the costs of the traversed edges is 20+10+70=100, so it satisfies the condition.
- There is no path from vertex 1 to vertex 2 that satisfies the condition. One path that traverses exactly three edges is vertex 1 \to vertex 2 \to vertex 1 \to vertex 2, but the sum of the costs of the edges traversed in this path is 20+30+20=70, which is less than 80, so it does not satisfy the condition.
- There is no path from vertex 1 to vertex 3 that satisfies the condition. One path that traverses exactly three edges is vertex 1 \to vertex 2 \to vertex 1 \to vertex 3, but the sum of the costs of the edges traversed in this path is 20+30+70=120, which is greater than 100, so it does not satisfy the condition.
- There is no path from vertex 1 to vertex 4 that satisfies the condition.
- For the path from vertex 1 to vertex 5, consider vertex 1 \to vertex 3 \to vertex 2 \to vertex 5 (right of the figure above). This traverses exactly three edges, and the sum of the costs of the traversed edges is 70+10+10=90, so it satisfies the condition.
Therefore, print 1, 5 in this order. Note that you need to print those vertices that satisfy the condition in ascending order.
Sample Input 2
10 1 1 1 100 2 3 1
Sample Output 2
If there are no vertices that satisfy the condition, print an empty line.
Sample Input 3
2 5 3 1 100 1 1 1 2 2 100 1 2 1 1 2 1 1 2 100
Sample Output 3
1 2
The graph may contain self-loops and multiple edges.
In this test case, the out-degrees from vertices 1 and 2 are 4 and 1, respectively.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
A, B, C の 3 種類の文字からなる長さ N の文字列 S が与えられます。
S の空でない連続する部分文字列は \dfrac{N(N+1)}2 個ありますが、そのうち A が B よりも多く含まれるものはいくつあるか求めてください。
2 つの部分文字列は、S から取り出す場所が異なれば文字列として等しくても区別して数えることに注意してください。
部分文字列とは
S の部分文字列とは、S の先頭から 0 文字以上、末尾から 0 文字以上削除して得られる文字列のことをいいます。
例えば、AB は ABC の部分文字列ですが、AC は ABC の部分文字列ではありません。
制約
- 1\le N\le5\times10 ^ 5
- S は
A,B,Cからなる長さ N の文字列 - N は整数
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の連続する部分文字列のうち A が B よりも多く含まれるものの個数を出力せよ。
入力例 1
10 ACBBCABCAB
出力例 1
8
以下の 8 つの部分文字列が条件を満たします。
A:S の 1 文字目から 1 文字目AC:S の 1 文字目から 2 文字目CA:S の 5 文字目から 6 文字目CABCA:S の 5 文字目から 9 文字目A:S の 6 文字目から 6 文字目ABCA:S の 6 文字目から 9 文字目CA:S の 8 文字目から 9 文字目A:S の 9 文字目から 9 文字目
これら以外の部分文字列は条件を満たさないため、8 を出力してください。
A や CA は複数箇所から取り出すことができますが、取り出す場所が異なれば区別して数えることに注意してください。
入力例 2
4 CCBC
出力例 2
0
条件を満たす部分文字列が存在しないこともあります。
入力例 3
36 CABACBBBBBAABABACCBCABCCABAABABBCBAC
出力例 3
136
Score : 450 points
Problem Statement
You are given a string S of length N consisting of three kinds of characters: A, B, and C.
There are \dfrac{N(N+1)}2 non-empty contiguous substrings of S. Find how many of them contain more As than Bs.
Note that two substrings are counted separately if they are taken from different positions in S, even if they are equal as strings.
What is a substring?
A substring of S is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of S.
For example, AB is a substring of ABC, but AC is not a substring of ABC.
Constraints
- 1\le N\le5\times10 ^ 5
- S is a string of length N consisting of
A,B, andC. - N is an integer.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the number of contiguous substrings of S that contain more As than Bs.
Sample Input 1
10 ACBBCABCAB
Sample Output 1
8
The following eight substrings satisfy the condition:
A: 1st to 1st character of SAC: 1st to 2nd character of SCA: 5th to 6th character of SCABCA: 5th to 9th character of SA: 6th to 6th character of SABCA: 6th to 9th character of SCA: 8th to 9th character of SA: 9th to 9th character of S
All other substrings do not satisfy the condition, so print 8.
Note that A and CA can be taken from multiple positions, but they are counted separately if taken from different positions.
Sample Input 2
4 CCBC
Sample Output 2
0
There may be no substrings that satisfy the condition.
Sample Input 3
36 CABACBBBBBAABABACCBCABCCABAABABBCBAC
Sample Output 3
136
実行時間制限: 2.5 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
ある店に N 個の商品が売られており、商品 1, 商品 2, \ldots, 商品 N と番号づけられています。
商品 i (1\leq i\leq N) の値段は P_i 円で、価値は V_i です。どの商品も 1 つずつしか存在しません。
高橋君は、値段の合計が M 円以下となる範囲でいくつかの商品を選びます。
ここで、M は任意の商品の値段以上であることが保証されます。
すなわち、任意の 1\leq i\leq N について、値段の合計が M 円以下となる選び方であって商品 i を含むようなものが必ず存在します。
このとき、1\leq i\leq N それぞれについて、商品 i が以下の 3 つの分類のどれに該当するか判定してください。
- 分類 A: (値段の合計が M 円以下となる範囲で)選んだ商品の価値の合計を最大にするには、その商品を必ず選ばなければならない。
- 分類 B: (値段の合計が M 円以下となる範囲で)選んだ商品の価値の合計を最大にするには、その商品を選んでも選ばなくてもよい。
- 分類 C: (値段の合計が M 円以下となる範囲で)選んだ商品の価値の合計を最大にするには、その商品を決して選んではならない。
制約
- 1\leq N\leq 1000
- 1\leq M\leq 5\times 10^4
- 1\leq P_i\leq M
- 1\leq V_i\leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M P_1 V_1 P_2 V_2 \vdots P_N V_N
出力
A,B,C からなる長さ N の文字列を出力せよ。
商品 i (1\leq i\leq N) が分類 X(X は A,B,C のいずれか)に該当するとき、出力する文字列の i 文字目が X となるようにせよ。
入力例 1
5 7 2 5 2 5 3 5 3 10 3 20
出力例 1
BBCBA
値段の合計が 7 円以下となる範囲で商品を選んだ時の価値の合計としてあり得る最大値は 30 であり、これは
- 商品 1 と商品 2 と商品 5 を選ぶ。
- 商品 4 と商品 5 を選ぶ。
のいずれかによって達成できます。(これ以外に値段の合計が 7 円以下かつ価値の合計が 30 となる選び方はありません。)
これより、各商品の分類は次のようになります。
- 商品 5 は、選んだ商品の価値の合計を最大にするには、必ず選ばなければならない商品(分類 A )です。
- 商品 1, 商品 2, 商品 4 は、選んだ商品の価値の合計を最大にするために、選んでも選ばなくてもよい商品(分類 B )です。
- 商品 3 は、選んだ商品の価値の合計を最大にするには、決して選んではならない商品(分類 C )です。
よって、出力形式に従って、BBCBA を出力します。
入力例 2
7 3 1 1 1 1 1 2 1 2 1 2 1 3 1 3
出力例 2
CCBBBAA
商品 3, 商品 4, 商品 5 のうちいずれか 1 つと、商品 6, 商品 7 を選んだ時に価値の合計が最大となります。
値段と価値がともに等しい商品であっても、商品としては区別されることに注意してください。
Score : 500 points
Problem Statement
A store sells N items, numbered as item 1, item 2, \ldots, item N.
Item i (1\leq i\leq N) has a price of P_i yen and a value of V_i. The store has only one stock of each item.
Takahashi chooses some items such that the total price is at most M yen.
Here, it is guaranteed that M is at least the price of any item.
That is, for any 1\leq i\leq N, there exists a way to choose items such that the total price is at most M yen and item i is included.
For each 1\leq i\leq N, determine which of the following three categories item i falls into:
- Category A: To maximize the total value of the chosen items (while keeping the total price at most M yen), that item must be chosen.
- Category B: To maximize the total value of the chosen items (while keeping the total price at most M yen), that item may or may not be chosen.
- Category C: To maximize the total value of the chosen items (while keeping the total price at most M yen), that item must never be chosen.
Constraints
- 1\leq N\leq 1000
- 1\leq M\leq 5\times 10^4
- 1\leq P_i\leq M
- 1\leq V_i\leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M P_1 V_1 P_2 V_2 \vdots P_N V_N
Output
Print a string of length N consisting of A, B, and C.
If item i (1\leq i\leq N) falls into category X (where X is A, B, or C), the i-th character of the output string should be X.
Sample Input 1
5 7 2 5 2 5 3 5 3 10 3 20
Sample Output 1
BBCBA
The maximum possible total value when choosing items such that the total price is at most 7 yen is 30, which can be achieved by one of the following:
- Choosing items 1, 2, and 5.
- Choosing items 4 and 5.
(There is no other way to choose items such that the total price is at most 7 yen and the total value is 30.)
Thus, the category of each item is as follows:
- Item 5 is an item that must be chosen to maximize the total value of the chosen items (category A).
- Items 1, 2, and 4 are items that may or may not be chosen to maximize the total value of the chosen items (category B).
- Item 3 is an item that must never be chosen to maximize the total value of the chosen items (category C).
Therefore, according to the output format, print BBCBA.
Sample Input 2
7 3 1 1 1 1 1 2 1 2 1 2 1 3 1 3
Sample Output 2
CCBBBAA
The total value is maximized when choosing any one of items 3, 4, 5, along with items 6 and 7.
Note that even if items have equal prices and values, they are still distinguished as different items.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 575 点
問題文
N 枚の皿が左から右に一直線状に並んでいます。 左から i 番目 (1\le i\le N) の皿を皿 i と呼ぶことにします。 はじめ、どの皿も表を上にして置かれており、どの皿にもたこ焼きが置かれていません。
次の 3 種類のクエリを合計 Q 回処理してください。
- タイプ 1:整数 L,R,X が与えられる。i=L,L+1,\ldots,R に対して、皿 i が表を上にして置かれているなら、皿 i にたこ焼きを X 個置く。
- タイプ 2:整数 L,R が与えられる。i=L,L+1,\ldots,R に対して、皿 i にたこ焼きが 1 個以上置かれていた場合、皿 i に置かれているたこ焼きをすべて食べる。皿 i をひっくり返す(皿が表を上にして置かれている場合裏を上にして置き、そうでない場合表を上にして置く)。
- タイプ 3:整数 L,R が与えられる。皿 L, 皿 L+1,\ldots, 皿 R にわたる、置かれているたこ焼きの個数の最大値を出力する。
制約
- 1\le N\le2\times10 ^ 5
- 1\le Q\le2\times10 ^ 5
- すべてのクエリにおいて、1\le L\le R\le N
- タイプ 1 のクエリにおいて、1\le X\le10 ^ 9
- タイプ 3 のクエリが存在する。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N Q
\mathrm{query} _ 1
\mathrm{query} _ 2
\vdots
\mathrm{query} _ Q
ここで、\mathrm{query} _ i は i 番目 (1\le i\le Q) のクエリを表し、次のどちらかの形式で与えられる。
t L R X
t L R
これらは、i 番目のクエリがタイプ t のクエリで、与えられる整数が L,R,X もしくは L,R であることを表す。 タイプ 1 のクエリは前者の形式で、それ以外のクエリは後者の形式で与えられる。
出力
タイプ 3 のクエリの個数を q として、q 行にわたって出力せよ。 i 行目 (1\le i\le q) には、タイプ 3 のクエリのうち先頭から i 番目のものに対する答えを出力せよ。
入力例 1
6 6 1 3 5 4 3 2 3 1 1 6 2 2 3 4 3 1 6 3 2 3
出力例 1
4 6 2
各クエリの時点で、それぞれの皿の状態とその上に置かれているたこ焼きの個数は以下の図のようになります。

2 番目のクエリの時点では、皿 2 と皿 3 のうち置かれているたこ焼きの個数がより多いのは皿 3 です。
よって、1 行目には皿 3 に置かれているたこ焼きの個数である 4 を出力してください。
5 番目のクエリの時点では、皿 1, 皿 2,\ldots, 皿 6 のうち置かれているたこ焼きの個数が最も多いのは皿 5 です。
よって、2 行目には皿 5 に置かれているたこ焼きの個数である 6 を出力してください。
6 番目のクエリの時点では、皿 2 と皿 3 のうち置かれているたこ焼きの個数がより多いのは皿 2 です。
よって、3 行目には皿 2 に置かれているたこ焼きの個数である 2 を出力してください。
入力例 2
2 8 1 1 2 1000000000 1 1 2 1000000000 2 2 2 1 1 2 1000000000 1 1 2 1000000000 1 1 2 1000000000 3 2 2 3 1 2
出力例 2
0 5000000000
裏を上にして置かれている皿にはひとつもたこ焼きは置かれないことに注意してください。
また、答えが 2 ^ {32} 以上になる場合があることに注意してください。
入力例 3
24 30 1 11 24 4326 1 4 16 1149 1 14 20 2331 1 12 14 8930 1 22 23 6989 3 15 20 3 10 19 1 3 12 7988 1 18 23 8450 3 9 19 3 13 15 2 8 15 2 9 14 1 11 17 4062 1 6 15 1721 3 7 13 1 11 20 8541 1 8 10 3748 1 1 17 3252 2 9 23 2 1 23 3 2 22 1 5 23 7468 3 1 12 3 12 19 2 6 24 3 2 14 3 1 15 2 15 19 3 2 14
出力例 3
7806 16736 22393 16736 10858 0 7468 7468 0 0 0
Score : 575 points
Problem Statement
N plates are arranged in a straight line from left to right. Let us call the i-th plate from the left (1\le i\le N) plate i. Initially, all plates are placed face-up, and no plates have takoyaki (octopus dumplings) on them.
Process a total of Q queries of the following three types:
- Type 1: You are given integers L,R,X. For i=L,L+1,\ldots,R, if plate i is placed face-up, place X takoyaki on plate i.
- Type 2: You are given integers L,R. For i=L,L+1,\ldots,R, if there is at least one takoyaki on plate i, eat all the takoyaki on plate i. Flip plate i (if the plate is placed face-up, place it face-down; otherwise, place it face-up).
- Type 3: You are given integers L,R. Print the maximum number of takoyaki on one plate among plates L, L+1,\ldots, R.
Constraints
- 1\le N\le2\times10 ^ 5
- 1\le Q\le2\times10 ^ 5
- In all queries, 1\le L\le R\le N.
- In type 1 queries, 1\le X\le10 ^ 9.
- There is at least one type 3 query.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q
\mathrm{query} _ 1
\mathrm{query} _ 2
\vdots
\mathrm{query} _ Q
Here, \mathrm{query} _ i represents the i-th (1\le i\le Q) query and is given in one of the following formats:
t L R X
t L R
These indicate that the i-th query is of type t and the given integers are L,R,X or L,R. Type 1 queries are given in the former format, and other queries are given in the latter format.
Output
Let q be the number of type 3 queries. Print q lines. The i-th line (1\le i\le q) should contain the answer to the i-th type 3 query from the beginning.
Sample Input 1
6 6 1 3 5 4 3 2 3 1 1 6 2 2 3 4 3 1 6 3 2 3
Sample Output 1
4 6 2
At the time of each query, the state of each plate and the number of takoyaki on it are as shown in the figure below.

At the time of the second query, among plates 2 and 3, the one with more takoyaki is plate 3.
Thus, print 4, the number of takoyaki on plate 3, on the first line.
At the time of the fifth query, among plates 1, 2,\ldots, 6, the one with the most takoyaki is plate 5.
Thus, print 6, the number of takoyaki on plate 5, on the second line.
At the time of the sixth query, among plates 2 and 3, the one with more takoyaki is plate 2.
Thus, print 2, the number of takoyaki on plate 2, on the third line.
Sample Input 2
2 8 1 1 2 1000000000 1 1 2 1000000000 2 2 2 1 1 2 1000000000 1 1 2 1000000000 1 1 2 1000000000 3 2 2 3 1 2
Sample Output 2
0 5000000000
Note that no takoyaki is placed on plates that are placed face-down.
Also, note that the answer may be 2 ^ {32} or more.
Sample Input 3
24 30 1 11 24 4326 1 4 16 1149 1 14 20 2331 1 12 14 8930 1 22 23 6989 3 15 20 3 10 19 1 3 12 7988 1 18 23 8450 3 9 19 3 13 15 2 8 15 2 9 14 1 11 17 4062 1 6 15 1721 3 7 13 1 11 20 8541 1 8 10 3748 1 1 17 3252 2 9 23 2 1 23 3 2 22 1 5 23 7468 3 1 12 3 12 19 2 6 24 3 2 14 3 1 15 2 15 19 3 2 14
Sample Output 3
7806 16736 22393 16736 10858 0 7468 7468 0 0 0