Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 150 点
問題文
英小文字と |
のみからなる文字列 S が与えられます。S は |
をちょうど 2 個含むことが保証されます。
2 つの |
の間にある文字および |
を S から削除した文字列を出力してください。
制約
- S は英小文字および
|
のみからなる長さ 2 以上 100 以下の文字列 - S は
|
をちょうど 2 個含む
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
atcoder|beginner|contest
出力例 1
atcodercontest
2 つの |
に挟まれた文字を全て削除して出力してください。
入力例 2
|spoiler|
出力例 2
全ての文字が削除されることもあります。
入力例 3
||xyz
出力例 3
xyz
Score: 150 points
Problem Statement
You are given a string S consisting of lowercase English letters and |
. S is guaranteed to contain exactly two |
s.
Remove the characters between the two |
s, including the |
s themselves, and print the resulting string.
Constraints
- S is a string of length between 2 and 100, inclusive, consisting of lowercase English letters and
|
. - S contains exactly two
|
s.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
atcoder|beginner|contest
Sample Output 1
atcodercontest
Remove all the characters between the two |
s and print the result.
Sample Input 2
|spoiler|
Sample Output 2
It is possible that all characters are removed.
Sample Input 3
||xyz
Sample Output 3
xyz
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 150 点
問題文
N 個の整数 A_1,A_2,\dots,A_N が、 1 行に 1 つずつ、 N 行にわたって与えられます。但し、 N は入力では与えられません。
さらに、以下が保証されます。
- A_i \neq 0 ( 1 \le i \le N-1 )
- A_N = 0
A_N, A_{N-1},\dots,A_1 をこの順に出力してください。
制約
- 入力は全て整数
- 1 \le N \le 100
- 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
- A_N = 0
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 \vdots A_N
出力
A_N, A_{N-1},\dots,A_1 をこの順に、改行区切りで整数として出力せよ。
入力例 1
3 2 1 0
出力例 1
0 1 2 3
繰り返しになりますが、 N は入力では与えられないことに注意してください。
この入力においては N=4 で、 A=(3,2,1,0) です。
入力例 2
0
出力例 2
0
A=(0) です。
入力例 3
123 456 789 987 654 321 0
出力例 3
0 321 654 987 789 456 123
Score: 150 points
Problem Statement
You are given N integers A_1,A_2,\dots,A_N, one per line, over N lines. However, N is not given in the input.
Furthermore, the following is guaranteed:
- A_i \neq 0 ( 1 \le i \le N-1 )
- A_N = 0
Print A_N, A_{N-1},\dots,A_1 in this order.
Constraints
- All input values are integers.
- 1 \le N \le 100
- 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
- A_N = 0
Input
The input is given from Standard Input in the following format:
A_1 A_2 \vdots A_N
Output
Print A_N, A_{N-1}, \dots, A_1 in this order, as integers, separated by newlines.
Sample Input 1
3 2 1 0
Sample Output 1
0 1 2 3
Note again that N is not given in the input. Here, N=4 and A=(3,2,1,0).
Sample Input 2
0
Sample Output 2
0
A=(0).
Sample Input 3
123 456 789 987 654 321 0
Sample Output 3
0 321 654 987 789 456 123
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 250 点
問題文
3 個の数列 A=(A_1,\ldots,A_N), B=(B_1,\ldots,B_M), C=(C_1,\ldots,C_L) が与えられます。
さらに数列 X=(X_1,\ldots,X_Q) が与えられるので、各 i=1,\ldots,Q に対して次の問題を解いてください。
問題:A,B,C からそれぞれ 1 個ずつ要素を選び、和を X_i にすることができるか?
制約
- 1 \leq N,M,L \leq 100
- 0 \leq A_i, B_i ,C_i \leq 10^8
- 1 \leq Q \leq 2\times 10^5
- 0 \leq X_i \leq 3\times 10^8
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N M B_1 \ldots B_M L C_1 \ldots C_L Q X_1 \ldots X_Q
出力
Q 行出力せよ。
i 行目には、A,B,C からそれぞれ 1 個ずつ要素を選び和を X_i にすることができるならば Yes
、できないならば No
と出力せよ。
入力例 1
3 1 2 3 2 2 4 6 1 2 4 8 16 32 4 1 5 10 50
出力例 1
No Yes Yes No
- A,B,C からそれぞれ 1 個ずつ要素を選び和を 1 にすることはできません。
- A,B,C からそれぞれ 1,2,2 を選ぶと和を 5 にすることができます。
- A,B,C からそれぞれ 2,4,4 を選ぶと和を 10 にすることができます。
- A,B,C からそれぞれ 1 個ずつ要素を選び和を 50 にすることはできません。
Score: 250 points
Problem Statement
You are given three sequences A=(A_1,\ldots,A_N), B=(B_1,\ldots,B_M), and C=(C_1,\ldots,C_L).
Additionally, a sequence X=(X_1,\ldots,X_Q) is given. For each i=1,\ldots,Q, solve the following problem:
Problem: Is it possible to select one element from each of A, B, and C so that their sum is X_i?
Constraints
- 1 \leq N,M,L \leq 100
- 0 \leq A_i, B_i ,C_i \leq 10^8
- 1 \leq Q \leq 2\times 10^5
- 0 \leq X_i \leq 3\times 10^8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N M B_1 \ldots B_M L C_1 \ldots C_L Q X_1 \ldots X_Q
Output
Print Q lines.
The i-th line should contain Yes
if it is possible to select one element from each of A, B, and C so that their sum is X_i, and No
otherwise.
Sample Input 1
3 1 2 3 2 2 4 6 1 2 4 8 16 32 4 1 5 10 50
Sample Output 1
No Yes Yes No
- It is impossible to select one element from each of A, B, and C so that their sum is 1.
- Selecting 1, 2, and 2 from A, B, and C, respectively, makes the sum 5.
- Selecting 2, 4, and 4 from A, B, and C, respectively, makes the sum 10.
- It is impossible to select one element from each of A, B, and C so that their sum is 50.
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 425 点
問題文
あなたは最初、空文字列 S を持っています。
さらに、文字列がいくつか入った袋 1,2,\dots,N があります。
袋 i には A_i 個の文字列 S_{i,1},S_{i,2},\dots,S_{i,A_i} が入っています。
これから、以下の手順を i=1,2,\dots,N について繰り返します。
- 以下のふたつの行動のうち、どちらかを選択して行う。
- 1 円を支払い、袋 i からちょうどひとつの文字列を選択して S の末尾に連結する。
- 何もしない。
文字列 T が与えられるとき、最終的に S と T を一致させるために必要な最小の金額を求めてください。
但し、どのようにしても最終的な S を T に一致させることができない場合、 -1
と出力してください。
制約
- T は長さ 1 以上 100 以下の英小文字からなる文字列
- N は 1 以上 100 以下の整数
- A_i は 1 以上 10 以下の整数
- S_{i,j} は長さ 1 以上 10 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
T N A_1 S_{1,1} S_{1,2} \dots S_{1,A_1} A_2 S_{2,1} S_{2,2} \dots S_{2,A_2} \vdots A_N S_{N,1} S_{N,2} \dots S_{N,A_N}
出力
答えを整数として出力せよ。
入力例 1
abcde 3 3 ab abc abcd 4 f c cd bcde 2 e de
出力例 1
2
例えば、以下のようにすると 2 円で最終的な S と T を一致させることができ、これが必要な金額の最低値であることが示せます。
- i=1 について、袋 1 から
abc
を選択し S の末尾に連結する。 S=abc
となる。 - i=2 について、何もしない。
- i=3 について、袋 3 から
de
を選択し S の末尾に連結する。 S=abcde
となる。
入力例 2
abcde 3 2 ab abc 3 f c bcde 1 e
出力例 2
-1
どのようにしても最終的な S と T を一致させることができないので、 -1
と出力してください。
入力例 3
aaabbbbcccc 6 2 aa aaa 2 dd ddd 2 ab aabb 4 bbaa bbbc bbb bbcc 2 cc bcc 3 ccc cccc ccccc
出力例 3
4
Score: 425 points
Problem Statement
You initially have an empty string S.
Additionally, there are bags 1, 2, \dots, N, each containing some strings.
Bag i contains A_i strings S_{i,1}, S_{i,2}, \dots, S_{i,A_i}.
You will repeat the following steps for i = 1, 2, \dots, N:
- Choose and perform one of the following two actions:
- Pay 1 yen, select exactly one string from bag i, and concatenate it to the end of S.
- Do nothing.
Given a string T, find the minimum amount of money required to make the final S equal T.
If there is no way to make the final S equal T, print -1
.
Constraints
- T is a string consisting of lowercase English letters with length between 1 and 100, inclusive.
- N is an integer between 1 and 100, inclusive.
- A_i is an integer between 1 and 10, inclusive.
- S_{i,j} is a string consisting of lowercase English letters with length between 1 and 10, inclusive.
Input
The input is given from Standard Input in the following format:
T N A_1 S_{1,1} S_{1,2} \dots S_{1,A_1} A_2 S_{2,1} S_{2,2} \dots S_{2,A_2} \vdots A_N S_{N,1} S_{N,2} \dots S_{N,A_N}
Output
Print the answer as an integer.
Sample Input 1
abcde 3 3 ab abc abcd 4 f c cd bcde 2 e de
Sample Output 1
2
For example, doing the following makes the final S equal T with two yen, which can be shown to be the minimum amount required.
- For i=1, select
abc
from bag 1 and concatenate it to the end of S, making S=abc
. - For i=2, do nothing.
- For i=3, select
de
from bag 3 and concatenate it to the end of S, making S=abcde
.
Sample Input 2
abcde 3 2 ab abc 3 f c bcde 1 e
Sample Output 2
-1
There is no way to make the final S equal T, so print -1
.
Sample Input 3
aaabbbbcccc 6 2 aa aaa 2 dd ddd 2 ab aabb 4 bbaa bbbc bbb bbcc 2 cc bcc 3 ccc cccc ccccc
Sample Output 3
4
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 475 点
問題文
長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。A の要素は相異なります。
Q 個のクエリが与えられるので順に処理してください。各クエリは次の 2 種類のどちらかです。
1 x y
: A 内の要素 x の直後に y を挿入する。このクエリが与えられる時点で、A には x が存在することが保証される。2 x
: A 内の要素 x を削除する。このクエリが与えられる時点で、A には x が存在することが保証される。
各クエリの処理後、A は空でなく、要素は相異なることが保証されます。
全てのクエリを処理した後の A を出力してください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq Q \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- A_i \neq A_j
- 1 種類目のクエリにおいて、1 \leq x,y \leq 10^9
- 1 種類目のクエリが与えられる時点で、A には x が存在する
- 2 種類目のクエリにおいて、1 \leq x \leq 10^9
- 2 種類目のクエリが与えられる時点で、A には x が存在する
- 各クエリの処理後、A は空でなく、要素は相異なる
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N Q \mathrm{Query}_1 \vdots \mathrm{Query}_Q
ここで \mathrm{Query}_i は i 番目のクエリを表し、次の形式で与えられる。
1 x y
2 x
出力
全てのクエリを処理したあとの数列 A を (A_1,\ldots,A_K) とする。A_1,\ldots,A_K をこの順に空白区切りで出力せよ。
入力例 1
4 2 1 4 3 4 2 1 1 4 5 2 2 1 5 1
出力例 1
4 5 1 3
クエリは次のように処理されます。
- 最初 A=(2,1,4,3) である。
- 1 番目のクエリにより 1 を削除する。A=(2,4,3) となる。
- 2 番目のクエリにより、4 の直後に 5 を挿入する。A=(2,4,5,3) となる。
- 3 番目のクエリにより 2 を削除する。A=(4,5,3) となる。
- 4 番目のクエリにより、5 の直後に 1 を挿入する。A=(4,5,1,3) となる。
入力例 2
6 3 1 4 5 9 2 7 2 5 1 3 5 1 9 7 2 9 2 3 1 2 3 2 4
出力例 2
5 1 7 2 3
Score: 475 points
Problem Statement
You are given a sequence A=(A_1,\ldots,A_N) of length N. The elements of A are distinct.
Process Q queries in the order they are given. Each query is of one of the following two types:
1 x y
: Insert y immediately after the element x in A. It is guaranteed that x exists in A when this query is given.2 x
: Remove the element x from A. It is guaranteed that x exists in A when this query is given.
It is guaranteed that after processing each query, A will not be empty, and its elements will be distinct.
Print A after processing all the queries.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq Q \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- A_i \neq A_j
- For queries of the first type, 1 \leq x,y \leq 10^9.
- When a query of the first type is given, x exists in A.
- For queries of the second type, 1 \leq x \leq 10^9.
- When a query of the second type is given, x exists in A.
- After processing each query, A is not empty, and its elements are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N Q \mathrm{Query}_1 \vdots \mathrm{Query}_Q
Here, \mathrm{Query}_i represents the i-th query and is given in one of the following formats:
1 x y
2 x
Output
Let A=(A_1,\ldots,A_K) be the sequence after processing all the queries. Print A_1,\ldots,A_K in this order, separated by spaces.
Sample Input 1
4 2 1 4 3 4 2 1 1 4 5 2 2 1 5 1
Sample Output 1
4 5 1 3
The queries are processed as follows:
- Initially, A=(2,1,4,3).
- The first query removes 1, making A=(2,4,3).
- The second query inserts 5 immediately after 4, making A=(2,4,5,3).
- The third query removes 2, making A=(4,5,3).
- The fourth query inserts 1 immediately after 5, making A=(4,5,1,3).
Sample Input 2
6 3 1 4 5 9 2 7 2 5 1 3 5 1 9 7 2 9 2 3 1 2 3 2 4
Sample Output 2
5 1 7 2 3
Time Limit: 4 sec / Memory Limit: 1024 MB
配点 : 550 点
問題文
縦 N 行横 N 列のグリッドがあります。上から i 行目、左から j 列目のマスをマス (i,j) と表します。
高橋君は最初マス (1,1) におり、所持金は 0 です。
高橋君はマス (i,j) にいるとき、1 回の行動で以下のいずれかを行うことができます。
- 同じマスにとどまり、所持金を P_{i,j} 増やす。
- 所持金から R_{i,j} 払ってマス (i,j+1) に移動する。
- 所持金から D_{i,j} 払ってマス (i+1,j) に移動する。
所持金が負になる移動、グリッドの外に出る移動はできません。
高橋君が最適に行動したとき、何回の行動でマス (N,N) にたどり着くことができますか。
制約
- 2 \leq N \leq 80
- 1 \leq P_{i,j} \leq 10^9
- 1 \leq R_{i,j},D_{i,j} \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N P_{1,1} \ldots P_{1,N} \vdots P_{N,1} \ldots P_{N,N} R_{1,1} \ldots R_{1,N-1} \vdots R_{N,1} \ldots R_{N,N-1} D_{1,1} \ldots D_{1,N} \vdots D_{N-1,1} \ldots D_{N-1,N}
出力
答えを出力せよ。
入力例 1
3 1 2 3 3 1 2 2 1 1 1 2 4 3 4 2 1 5 7 5 3 3
出力例 1
8
以下のようにして 8 回の行動でマス (3,3) にたどり着くことができます。
- マス (1,1) にとどまり、所持金を 1 増やす。所持金は 1 になる。
- 所持金から 1 払ってマス (2,1) に移動する。所持金は 0 になる。
- マス (2,1) にとどまり、所持金を 3 増やす。所持金は 3 になる。
- マス (2,1) にとどまり、所持金を 3 増やす。所持金は 6 になる。
- マス (2,1) にとどまり、所持金を 3 増やす。所持金は 9 になる。
- 所持金から 4 払ってマス (2,2) に移動する。所持金は 5 になる。
- 所持金から 3 払ってマス (3,2) に移動する。所持金は 2 になる。
- 所持金から 2 払ってマス (3,3) に移動する。所持金は 0 になる。
入力例 2
3 1 1 1 1 1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 2
4000000004
Score: 550 points
Problem Statement
There is a grid with N rows and N columns. Let (i,j) denote the square at the i-th row from the top and j-th column from the left.
Takahashi is initially at square (1,1) with zero money.
When Takahashi is at square (i,j), he can perform one of the following in one action:
- Stay at the same square and increase his money by P_{i,j}.
- Pay R_{i,j} from his money and move to square (i,j+1).
- Pay D_{i,j} from his money and move to square (i+1,j).
He cannot make a move that would make his money negative or take him outside the grid.
If Takahashi acts optimally, how many actions does he need to reach square (N,N)?
Constraints
- 2 \leq N \leq 80
- 1 \leq P_{i,j} \leq 10^9
- 1 \leq R_{i,j},D_{i,j} \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N P_{1,1} \ldots P_{1,N} \vdots P_{N,1} \ldots P_{N,N} R_{1,1} \ldots R_{1,N-1} \vdots R_{N,1} \ldots R_{N,N-1} D_{1,1} \ldots D_{1,N} \vdots D_{N-1,1} \ldots D_{N-1,N}
Output
Print the answer.
Sample Input 1
3 1 2 3 3 1 2 2 1 1 1 2 4 3 4 2 1 5 7 5 3 3
Sample Output 1
8
It is possible to reach square (3,3) in eight actions as follows:
- Stay at square (1,1) and increase money by 1. His money is now 1.
- Pay 1 money and move to square (2,1). His money is now 0.
- Stay at square (2,1) and increase money by 3. His money is now 3.
- Stay at square (2,1) and increase money by 3. His money is now 6.
- Stay at square (2,1) and increase money by 3. His money is now 9.
- Pay 4 money and move to square (2,2). His money is now 5.
- Pay 3 money and move to square (3,2). His money is now 2.
- Pay 2 money and move to square (3,3). His money is now 0.
Sample Input 2
3 1 1 1 1 1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 2
4000000004
Time Limit: 10 sec / Memory Limit: 1024 MB
配点 : 625 点
問題文
特殊な入力形式に注意してください。
xy 平面上に N 個の点 (X_i,Y_i) があります。これらの点の情報は入力から与えられます。
また、 Q 個の整数組 (A_j,B_j) が与えられます。
f(A_j,B_j) を Y_i \ge A_j \times X_i + B_j を満たす i の個数として定義します。
\displaystyle \sum^{Q}_{j=1} f(A_j,B_j) を求めてください。
但し、この問題では Q が非常に大きくなるため、 (A_j,B_j) は直接与えられません。
代わりに G_0,R_a,R_b が与えられ、 (A_j,B_j) は以下の方法で生成されます。
- まず、 n \ge 0 に対して、 G_{n+1} = (48271 \times G_n) \mod (2^{31}-1) と定義します。
- j=1,2,\dots,Q に対して、 (A_j,B_j) を次のように生成します。
- A_j = -R_a + (G_{3j - 2} \mod (2 \times R_a + 1) )
- B_j = -R_b + ((G_{3j - 1} \times (2^{31}-1) + G_{3 j}) \mod (2 \times R_b + 1) )
この生成法から、 A_j, B_j は以下の制約を満たすことが示せます。
- -R_a \le A_j \le R_a
- -R_b \le B_j \le R_b
制約
- 入力は全て整数
- 1 \le N \le 5000
- 1 \le Q \le 10^7
- |X_i|, |Y_i| \le 10^8
- (X_i,Y_i) は相異なる
- 0 \le G_0 < (2^{31}-1)
- 0 \le R_a \le 10^8
- 0 \le R_b \le 10^{16}
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 X_2 Y_2 \vdots X_N Y_N Q G_0 R_a R_b
出力
答えを整数として出力せよ。
入力例 1
7 2 -2 -1 -2 0 1 2 1 -2 2 1 2 0 -1 10 1 5 5
出力例 1
36
この入力には 10 個の質問が含まれます。
生成された (A_j,B_j) は (-2,4),(0,2),(-4,-2),(4,-5),(3,1),(-1,3),(2,-5),(3,-1),(3,5),(3,-2) です。
Score: 625 points
Problem Statement
Pay attention to the special input format.
There are N points (X_i,Y_i) in the xy-plane. You are given these points in the input.
Also, Q pairs of integers (A_j,B_j) are given.
Define f(A_j,B_j) as the number of indices i satisfying Y_i \ge A_j \times X_i + B_j.
Find \displaystyle \sum^{Q}_{j=1} f(A_j,B_j).
Here, Q gets very large, so (A_j,B_j) are not given directly.
Instead, G_0, R_a, and R_b are given, and (A_j,B_j) are generated as follows:
- First, for n \ge 0, define G_{n+1} = (48271 \times G_n) \mod (2^{31}-1).
- For j=1,2,\dots,Q, generate (A_j,B_j) as follows:
- A_j = -R_a + (G_{3j - 2} \mod (2 \times R_a + 1) )
- B_j = -R_b + ((G_{3j - 1} \times (2^{31}-1) + G_{3 j}) \mod (2 \times R_b + 1) )
From this method, it can be shown that A_j and B_j satisfy the following constraints:
- -R_a \le A_j \le R_a
- -R_b \le B_j \le R_b
Constraints
- All input values are integers.
- 1 \le N \le 5000
- 1 \le Q \le 10^7
- |X_i|, |Y_i| \le 10^8
- The pairs (X_i,Y_i) are distinct.
- 0 \le G_0 < (2^{31}-1)
- 0 \le R_a \le 10^8
- 0 \le R_b \le 10^{16}
Input
The input is given from Standard Input in the following format:
N X_1 Y_1 X_2 Y_2 \vdots X_N Y_N Q G_0 R_a R_b
Output
Print the answer as an integer.
Sample Input 1
7 2 -2 -1 -2 0 1 2 1 -2 2 1 2 0 -1 10 1 5 5
Sample Output 1
36
This input contains ten questions.
The generated (A_j,B_j) are (-2,4),(0,2),(-4,-2),(4,-5),(3,1),(-1,3),(2,-5),(3,-1),(3,5),(3,-2).