実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
一台のバスが走っています。バスの乗客の数は常に非負整数です。
このバスにはある時点で 0 人以上の乗客が乗っており、その時点から現在までに N 回停車しました。このうち i 回目の停車では乗客が差し引き A_i 人増えました。A_i は負の値であることもあり、その場合は乗客が差し引き -A_i 人減ったことを意味しています。また、停車時以外には乗客の乗り降りはありませんでした。
与えられた情報に矛盾しない現在のバスの乗客の数として考えられる最小値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq A_i \leq 10^9
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 3 -5 7 -4
出力例 1
3
はじめに乗っている乗客の人数が 2 人であるとき、現在の乗客の人数は 2 + 3 + (-5) + 7 + (-4) = 3 人であり、さらにバスの乗客の人数は常に非負整数となります。
入力例 2
5 0 0 0 0 0
出力例 2
0
入力例 3
4 -1 1000000000 1000000000 1000000000
出力例 3
3000000000
Score: 250 points
Problem Statement
A bus is in operation. The number of passengers on the bus is always a non-negative integer.
At some point in time, the bus had zero or more passengers, and it has stopped N times since then. At the i-th stop, the number of passengers increased by A_i. Here, A_i can be negative, meaning the number of passengers decreased by -A_i. Also, no passengers got on or off the bus other than at the stops.
Find the minimum possible current number of passengers on the bus that is consistent with the given information.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq A_i \leq 10^9
- All input values 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 answer.
Sample Input 1
4 3 -5 7 -4
Sample Output 1
3
If the initial number of passengers was 2, the current number of passengers would be 2 + 3 + (-5) + 7 + (-4) = 3, and the number of passengers on the bus would have always been a non-negative integer.
Sample Input 2
5 0 0 0 0 0
Sample Output 2
0
Sample Input 3
4 -1 1000000000 1000000000 1000000000
Sample Output 3
3000000000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
AtCoder Land には 1 から N までの番号が付けられた N 個のポップコーン売り場があります。 売られているポップコーンの味には味 1,2,\dots,M の M 種類がありますが、すべての売り場ですべての味のポップコーンを売っているわけではありません。
高橋君は、それぞれのポップコーン売り場でどの味のポップコーンを売っているかの情報を入手しました。
この情報は N 個の長さ M の文字列 S_1,S_2,\dots,S_N によって表され、S_i の j 文字目が o
であるとき売り場 i が味 j のポップコーンを売っていることを、
x
であるとき売っていないことを示します。
どの売り場も最低 1 種類の味のポップコーンを売っており、どの味のポップコーンも最低 1 つの売り場で売られています。
高橋君は全種類のポップコーンを食べたがっていますが、あまり何度も移動はしたくありません。 高橋君がすべての味のポップコーンを購入するためには最低何個の売り場を訪れる必要があるか求めてください。
制約
- N,M は整数
- 1\leq N,M \leq 10
- S_i は
o
およびx
からなる長さ M の文字列 - すべての i\ (1\leq i\leq N) について、S_i の中には
o
が 1 つ以上存在する - すべての j\ (1\leq j\leq M) について、S_i の j 文字目が
o
であるような i が 1 つ以上存在する
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
高橋君がすべての味のポップコーンを購入するために訪れる必要がある売り場の個数の最小値を出力せよ。
入力例 1
3 5 oooxx xooox xxooo
出力例 1
2
1 つめの売り場と 3 つめの売り場を訪れることで、すべての味のポップコーンを購入することができます。 1 つの売り場ですべての味のポップコーンを購入することはできないので、答えは 2 です。
入力例 2
3 2 oo ox xo
出力例 2
1
入力例 3
8 6 xxoxxo xxoxxx xoxxxx xxxoxx xxoooo xxxxox xoxxox oxoxxo
出力例 3
3
Score : 300 points
Problem Statement
In AtCoder Land, there are N popcorn stands numbered 1 to N. They have M different flavors of popcorn, labeled 1, 2, \dots, M, but not every stand sells all flavors of popcorn.
Takahashi has obtained information about which flavors of popcorn are sold at each stand. This information is represented by N strings S_1, S_2, \dots, S_N of length M. If the j-th character of S_i is o
, it means that stand i sells flavor j of popcorn. If it is x
, it means that stand i does not sell flavor j. Each stand sells at least one flavor of popcorn, and each flavor of popcorn is sold at least at one stand.
Takahashi wants to try all the flavors of popcorn but does not want to move around too much. Determine the minimum number of stands Takahashi needs to visit to buy all the flavors of popcorn.
Constraints
- N and M are integers.
- 1 \leq N, M \leq 10
- Each S_i is a string of length M consisting of
o
andx
. - For every i (1 \leq i \leq N), there is at least one
o
in S_i. - For every j (1 \leq j \leq M), there is at least one i such that the j-th character of S_i is
o
.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Print the minimum number of stands Takahashi needs to visit to buy all the flavors of popcorn.
Sample Input 1
3 5 oooxx xooox xxooo
Sample Output 1
2
By visiting the 1st and 3rd stands, you can buy all the flavors of popcorn. It is impossible to buy all the flavors from a single stand, so the answer is 2.
Sample Input 2
3 2 oo ox xo
Sample Output 2
1
Sample Input 3
8 6 xxoxxo xxoxxx xoxxxx xxxoxx xxoooo xxxxox xoxxox oxoxxo
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は 10^{100} 個の植木鉢を持っています。最初、高橋君は植物を 1 個も育てていません。
Q 個のクエリが与えられるので、順に処理してください。
クエリは次の 3 種類です。
1
: 植物が植えられていない植木鉢を 1 個用意し、その植木鉢に植物を植える。このとき植物の高さは 0 である。2 T
: T 日待つ。このとき植えてあるすべての植物の高さが T 増加する。3 H
: 高さが H 以上の植物をすべて収穫し、収穫した植物の数を出力する。収穫した植物は植木鉢から取り除かれる。
ただし、高橋君が 1 種類目と 3 種類目のクエリを行うとき、かかる時間は 0 であるとします。
制約
- 1 \leq Q \leq 2 \times 10^{5}
- 1 \leq T,H \leq 10^{9}
- 3 種類目のクエリが 1 つ以上存在する
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
Q \text{query}_1 \text{query}_2 \vdots \text{query}_Q
各クエリは以下のいずれかの形式で与えられる。
1
2 T
3 H
出力
3 種類目のクエリが K 個あるとき、K 行出力せよ。 i 行目 (1\leq i\leq K) には、i 個目の 3 種類目のクエリに対する答えを出力せよ。
入力例 1
6 1 2 15 1 3 10 2 20 3 20
出力例 1
1 1
クエリは次の順で処理されます。
- 1 個目のクエリでは高さ 0 の植物が 1 個植えられます。
- 2 個目のクエリでは高さ 0 の植物が高さ 15 になります。
- 3 個目のクエリでは高さ 0 の植物が 1 個植えられます。このとき、高さ 0 と高さ 15 の植物が 1 個ずつあります。
- 4 個目のクエリでは高さ 10 以上の植物が収穫されます。このとき、高さ 15 の植物が 1 個収穫されて高さ 0 の植物が 1 個残ります。1 個の植物を収穫したため、1 行目に 1 と出力します。
- 5 個目のクエリでは高さ 0 の植物が高さ 20 になります。
- 6 個目のクエリでは高さ 20 以上の植物が収穫されます。このとき、高さ 20 の植物が 1 個収穫されます。よって、2 行目に 1 と出力します。
入力例 2
15 1 1 2 226069413 3 1 1 1 2 214168203 1 3 214168203 1 1 1 2 314506461 2 245642315 3 1
出力例 2
2 2 4
Score : 400 points
Problem Statement
Takahashi has 10^{100} flower pots. Initially, he is not growing any plants.
You are given Q queries to process in order.
There are three types of queries as follows.
1
: Prepare one empty flower pot and put a plant in it. Here, the plant's height is 0.2 T
: Wait for T days. During this time, the height of every existing plants increases by T.3 H
: Harvest all plants with a height of at least H, and output the number of plants harvested. The harvested plants are removed from their flower pots.
Assume that performing queries of the first and third types takes zero time.
Constraints
- 1 \leq Q \leq 2 \times 10^{5}
- 1 \leq T,H \leq 10^{9}
- There is at least one query of the third type.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Q \text{query}_1 \text{query}_2 \vdots \text{query}_Q
Each query is given in one of the following formats:
1
2 T
3 H
Output
Let there be K queries of the third type, and print K lines. The i-th line (1 \leq i \leq K) should contain the answer to the i-th query of type 3.
Sample Input 1
6 1 2 15 1 3 10 2 20 3 20
Sample Output 1
1 1
Queries are processed in the following order:
- In the first query, a plant of height 0 is planted.
- In the second query, the height of the plant increases to 15.
- In the third query, another plant of height 0 is planted. Now there is one plant of height 15 and one plant of height 0.
- In the fourth query, all plants with height at least 10 are harvested. Here, one plant of height 15 gets harvested, and one plant of height 0 remains. Since one plant was harvested, print 1 on the first line.
- In the fifth query, the height of the remaining plant increases to 20.
- In the sixth query, all plants with height at least 20 are harvested. Here, one plant of height 20 gets harvested. Thus, print 1 on the second line.
Sample Input 2
15 1 1 2 226069413 3 1 1 1 2 214168203 1 3 214168203 1 1 1 2 314506461 2 245642315 3 1
Sample Output 2
2 2 4
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
長さ N の非負整数列 A および整数 K が与えられます。ここで二項係数 \dbinom{N}{K} は 10^6 以下であることが保証されます。
A から異なる K 項を選ぶとき、選んだ K 個の数の総 XOR としてあり得る最大値を求めてください。
すなわち \underset{1\leq i_1\lt i_2\lt \ldots\lt i_K\leq N}{\max} A_{i_1}\oplus A_{i_2}\oplus \ldots \oplus A_{i_K} を求めてください。
XOR とは
非負整数 A,B の XOR A \oplus B は、以下のように定義されます。- A \oplus B を二進表記した際の 2^k \, (k \geq 0) の位の数は、A,B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
一般に k 個の整数 p_1, \dots, p_k の XOR は (\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k) と定義され、これは p_1, \dots, p_k の順番によらないことが証明できます。
制約
- 1\leq K\leq N\leq 2\times 10^5
- 0\leq A_i\lt 2^{60}
- \dbinom{N}{K}\leq 10^6
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 2 3 2 6 4
出力例 1
7
(3,2,6,4) から異なる 2 つの項を選ぶ方法は以下の 6 通りあります。
- (3,2) のとき、選んだ数の総 XOR は 3\oplus 2 = 1 です。
- (3,6) のとき、選んだ数の総 XOR は 3\oplus 6 = 5 です。
- (3,4) のとき、選んだ数の総 XOR は 3\oplus 4 = 7 です。
- (2,6) のとき、選んだ数の総 XOR は 2\oplus 6 = 4 です。
- (2,4) のとき、選んだ数の総 XOR は 2\oplus 4 = 6 です。
- (6,4) のとき、選んだ数の総 XOR は 6\oplus 4 = 2 です。
よって、求める最大値は 7 です。
入力例 2
10 4 1516 1184 1361 2014 1013 1361 1624 1127 1117 1759
出力例 2
2024
Score : 500 points
Problem Statement
You are given a sequence A of non-negative integers of length N, and an integer K. It is guaranteed that the binomial coefficient \dbinom{N}{K} is at most 10^6.
When choosing K distinct elements from A, find the maximum possible value of the XOR of the K chosen elements.
That is, find \underset{1\leq i_1\lt i_2\lt \ldots\lt i_K\leq N}{\max} A_{i_1}\oplus A_{i_2}\oplus \ldots \oplus A_{i_K}.
About XOR
For non-negative integers A,B, the XOR A \oplus B is defined as follows:- In the binary representation of A \oplus B, the bit corresponding to 2^k (k \ge 0) is 1 if and only if exactly one of the bits corresponding to 2^k in A and B is 1, and is 0 otherwise.
In general, the XOR of K integers p_1, \dots, p_k is defined as (\cdots((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k). It can be proved that it does not depend on the order of p_1, \dots, p_k.
Constraints
- 1\leq K\leq N\leq 2\times 10^5
- 0\leq A_i<2^{60}
- \dbinom{N}{K}\leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
4 2 3 2 6 4
Sample Output 1
7
Here are six ways to choose two distinct elements from (3,2,6,4).
- (3,2): The XOR is 3\oplus 2 = 1.
- (3,6): The XOR is 3\oplus 6 = 5.
- (3,4): The XOR is 3\oplus 4 = 7.
- (2,6): The XOR is 2\oplus 6 = 4.
- (2,4): The XOR is 2\oplus 4 = 6.
- (6,4): The XOR is 6\oplus 4 = 2.
Hence, the maximum possible value is 7.
Sample Input 2
10 4 1516 1184 1361 2014 1013 1361 1624 1127 1117 1759
Sample Output 2
2024
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 550 点
問題文
英大小文字と (
、 )
からなる文字列 S=S_1 S_2 S_3 \dots S_{|S|} が与えられます。
文字列 S 中の括弧は、対応が取れています。
次の操作を、操作ができなくなるまで繰り返します。
- まず、以下の条件を全て満たす整数組 (l,r) をひとつ選択する。
- l < r
- S_l =
(
- S_r =
)
- S_{l+1},S_{l+2},\dots,S_{r-1} は全て英大文字または英小文字である
- T=\overline{S_{r-1}S_{r-2} \dots S_{l+1}} とする。
- 但し、 \overline{x} は x の大文字と小文字を反転させた文字列を指す。
- その後、 S の l 文字目から r 文字目までを削除し、削除した位置に T を挿入する。
詳細は入出力例を参照してください。
上記の操作を使って全ての (
と )
を除去することができ、最終的な文字列は操作の方法や順序によらないことが証明できます。
このとき、最終的な文字列を求めてください。
「 S 中の括弧の対応が取れている」とは?
まず、正しい括弧列を次の通り定義します。- 正しい括弧列とは、以下のいずれかの条件を満たす文字列です。
- 空文字列
- ある正しい括弧列 A が存在して、
(
, A,)
をこの順に連結した文字列 - ある空でない正しい括弧列 A,B が存在して、 A,B をこの順に連結した文字列
(
と )
を順序を保って抜き出した時、それが正しい括弧列となることを指す。
制約
- 1 \le |S| \le 5 \times 10^5
- S は英大小文字と
(
、)
からなる - S 中の括弧は対応が取れている
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
((A)y)x
出力例 1
YAx
S= ((A)y)x
に対して操作を行います。
- l=2,r=4 を選択します。このとき削除される文字列は
(A)
で、代わりにa
が挿入されます。- この操作の結果、 S=
(ay)x
となります。
- この操作の結果、 S=
- l=1,r=4 を選択します。このとき削除される文字列は
(ay)
で、代わりにYA
が挿入されます。- この操作の結果、 S=
YAx
となります。
- この操作の結果、 S=
括弧を除去した結果、文字列は YAx
となったので、これを出力してください。
入力例 2
((XYZ)n(X(y)Z))
出力例 2
XYZNXYZ
S= ((XYZ)n(X(y)Z))
に対して操作を行います。
- l=10,r=12 を選択します。このとき削除される文字列は
(y)
で、代わりにY
が挿入されます。- この操作の結果、 S=
((XYZ)n(XYZ))
となります。
- この操作の結果、 S=
- l=2,r=6 を選択します。このとき削除される文字列は
(XYZ)
で、代わりにzyx
が挿入されます。- この操作の結果、 S=
(zyxn(XYZ))
となります。
- この操作の結果、 S=
- l=6,r=10 を選択します。このとき削除される文字列は
(XYZ)
で、代わりにzyx
が挿入されます。- この操作の結果、 S=
(zyxnzyx)
となります。
- この操作の結果、 S=
- l=1,r=9 を選択します。このとき削除される文字列は
(zyxnzyx)
で、代わりにXYZNXYZ
が挿入されます。- この操作の結果、 S=
XYZNXYZ
となります。
- この操作の結果、 S=
括弧を除去した結果、文字列は XYZNXYZ
となったので、これを出力してください。
入力例 3
(((()))(()))(())
出力例 3
操作結果が空文字列になる場合もあります。
入力例 4
dF(qT(plC())NnnfR(GsdccC))PO()KjsiI((ysA)eWW)ve
出力例 4
dFGsdccCrFNNnplCtQPOKjsiIwwEysAve
Score: 550 points
Problem Statement
You are given a string S = S_1 S_2 S_3 \dots S_{|S|} consisting of uppercase and lowercase English letters, (
, and )
.
The parentheses in the string S are properly matched.
Repeat the following operation until no more operations can be performed:
- First, select one pair of integers (l, r) that satisfies all of the following conditions:
- l < r
- S_l =
(
- S_r =
)
- Each of the characters S_{l+1}, S_{l+2}, \dots, S_{r-1} is an uppercase or lowercase English letter.
- Let T = \overline{S_{r-1} S_{r-2} \dots S_{l+1}}.
- Here, \overline{x} denotes the string obtained by toggling the case of each character in x (uppercase to lowercase and vice versa).
- Then, delete the l-th through r-th characters of S and insert T at the position where the deletion occurred.
Refer to the sample inputs and outputs for clarification.
It can be proved that it is possible to remove all (
s and )
s from the string using the above operations, and the final string is independent of how and in what order the operations are performed.
Determine the final string.
What does it mean that the parentheses in S are properly matched?
First, a correct parenthesis sequence is defined as follows:- A correct parenthesis sequence is a string that satisfies one of the following conditions:
- It is an empty string.
- There exists a correct parenthesis sequence A, and the string is formed by concatenating
(
, A,)
in this order. - There exist non-empty correct parenthesis sequences A and B, and the string is formed by concatenating A and B in this order.
(
s and )
s extracted from S without changing the order form a correct parenthesis sequence.
Constraints
- 1 \le |S| \le 5 \times 10^5
- S consists of uppercase and lowercase English letters,
(
, and)
. - The parentheses in S are properly matched.
Input
The input is given from Standard Input in the following format:
S
Output
Print the final string.
Sample Input 1
((A)y)x
Sample Output 1
YAx
Let us perform the operations for S = ((A)y)x
.
- Choose l=2 and r=4. The substring
(A)
is removed and replaced witha
.- After this operation, S =
(ay)x
.
- After this operation, S =
- Choose l=1 and r=4. The substring
(ay)
is removed and replaced withYA
.- After this operation, S =
YAx
.
- After this operation, S =
After removing the parentheses, the string becomes YAx
, which should be printed.
Sample Input 2
((XYZ)n(X(y)Z))
Sample Output 2
XYZNXYZ
Let us perform the operations for S = ((XYZ)n(X(y)Z))
.
- Choose l=10 and r=12. The substring
(y)
is removed and replaced withY
.- After this operation, S =
((XYZ)n(XYZ))
.
- After this operation, S =
- Choose l=2 and r=6. The substring
(XYZ)
is removed and replaced withzyx
.- After this operation, S =
(zyxn(XYZ))
.
- After this operation, S =
- Choose l=6 and r=10. The substring
(XYZ)
is removed and replaced withzyx
.- After this operation, S =
(zyxnzyx)
.
- After this operation, S =
- Choose l=1 and r=9. The substring
(zyxnzyx)
is removed and replaced withXYZNXYZ
.- After this operation, S =
XYZNXYZ
.
- After this operation, S =
After removing the parentheses, the string becomes XYZNXYZ
, which should be printed.
Sample Input 3
(((()))(()))(())
Sample Output 3
The final outcome may be an empty string.
Sample Input 4
dF(qT(plC())NnnfR(GsdccC))PO()KjsiI((ysA)eWW)ve
Sample Output 4
dFGsdccCrFNNnplCtQPOKjsiIwwEysAve