実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
8 個の整数 S_1,S_2,\dots,S_8 が与えられます。
以下の 3 つの条件が全て満たされるならば Yes を、そうでないならば No を出力してください。
- 数列 (S_1,S_2,\dots,S_8) は広義単調増加である。すなわち、S_1 \leq S_2 \leq \dots \leq S_8 である。
- S_1,S_2,\dots,S_8 は全て 100 以上 675 以下である。
- S_1,S_2,\dots,S_8 は全て 25 の倍数である。
制約
- 0\leq S_i \leq 1000
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 \dots S_8
出力
答えを出力せよ。
入力例 1
125 175 250 300 400 525 600 650
出力例 1
Yes
3 つの条件を全て満たしています。
入力例 2
100 250 300 400 325 575 625 675
出力例 2
No
S_4 > S_5 であるため、1 つ目の条件を満たしていません。
入力例 3
0 23 24 145 301 413 631 632
出力例 3
No
2 つ目の条件と 3 つ目の条件を満たしていません。
Score : 100 points
Problem Statement
Given eight integers S_1,S_2,\dots, and S_8,
print Yes if they satisfy all of the following three conditions, and No otherwise.
- The sequence (S_1,S_2,\dots,S_8) is monotonically non-decreasing. In other words, S_1 \leq S_2 \leq \dots \leq S_8.
- S_1,S_2,\dots, and S_8 are all between 100 and 675, inclusive.
- S_1,S_2,\dots, and S_8 are all multiples of 25.
Constraints
- 0\leq S_i \leq 1000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
S_1 S_2 \dots S_8
Output
Print the answer.
Sample Input 1
125 175 250 300 400 525 600 650
Sample Output 1
Yes
They satisfy all of the three conditions.
Sample Input 2
100 250 300 400 325 575 625 675
Sample Output 2
No
They violate the first condition because S_4 > S_5.
Sample Input 3
0 23 24 145 301 413 631 632
Sample Output 3
No
They violate the second and third conditions.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
文字列 atcoder の L 文字目から R 文字目までを出力してください。
制約
- L,R は整数
- 1 \le L \le R \le 7
入力
入力は以下の形式で標準入力から与えられる。
L R
出力
答えを出力せよ。
入力例 1
3 6
出力例 1
code
atcoder の 3 文字目から 6 文字目までを出力すると code となります。
入力例 2
4 4
出力例 2
o
入力例 3
1 7
出力例 3
atcoder
Score : 100 points
Problem Statement
Print the L-th through R-th characters of the string atcoder.
Constraints
- L and R are integers.
- 1 \le L \le R \le 7
Input
Input is given from Standard Input in the following format:
L R
Output
Print the answer.
Sample Input 1
3 6
Sample Output 1
code
The 3-rd through 6-th characters of atcoder are code.
Sample Input 2
4 4
Sample Output 2
o
Sample Input 3
1 7
Sample Output 3
atcoder
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
健康に気を使っている高橋君は、M 種類の栄養素について、食事によって十分な量を摂取できているか気になりました。
i 番目の栄養素は 1 日あたり A_i 以上摂取することが目標です。
高橋君は今日 N 品の食品を食べ、i 品目の食品からは栄養素 j を X_{i,j} 摂取しました。
M 種類全ての栄養素で目標を達成しているかどうかを判定してください。
制約
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 0 \leq A_i,X_{i,j} \leq 10^7
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M
A_1 \ldots A_M
X_{1,1} \ldots X_{1,M}
\vdots
X_{N,1} \ldots X_{N,M}
出力
M 種類全ての栄養素で目標を達成しているなら Yes、そうでないならば No を出力せよ。
入力例 1
2 3 10 20 30 20 0 10 0 100 100
出力例 1
Yes
栄養素 1 は 1 品目から 20、2 品目から 0 摂取したため、合わせて 20 摂取しており、10 以上摂取するという目標を達成しています。
栄養素 2,3 についても同様に目標を達成しています。
入力例 2
2 4 10 20 30 40 20 0 10 30 0 100 100 0
出力例 2
No
栄養素 4 について目標を達成していません。
Score : 150 points
Problem Statement
Takahashi is health-conscious and concerned about whether he is getting enough of M types of nutrients from his diet.
For the i-th nutrient, his goal is to take at least A_i units per day.
Today, he ate N foods, and from the i-th food, he took X_{i,j} units of nutrient j.
Determine whether he has met the goal for all M types of nutrients.
Constraints
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 0 \leq A_i, X_{i,j} \leq 10^7
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
A_1 \ldots A_M
X_{1,1} \ldots X_{1,M}
\vdots
X_{N,1} \ldots X_{N,M}
Output
Print Yes if the goal is met for all M types of nutrients, and No otherwise.
Sample Input 1
2 3 10 20 30 20 0 10 0 100 100
Sample Output 1
Yes
For nutrient 1, Takahashi took 20 units from the 1-st food and 0 units from the 2-nd food, totaling 20 units, thus meeting the goal of taking at least 10 units.
Similarly, he meets the goal for nutrients 2 and 3.
Sample Input 2
2 4 10 20 30 40 20 0 10 30 0 100 100 0
Sample Output 2
No
The goal is not met for nutrient 4.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
1,2,\ldots,N と番号づけられた N 人が M 回、一列に並んで集合写真を撮りました。i 番目の撮影で左から j 番目に並んだ人の番号は a_{i,j} です。
ある二人組は M 回の撮影で一度も連続して並ばなかった場合、不仲である可能性があります。
不仲である可能性がある二人組の個数を求めてください。なお、人 x と人 y からなる二人組と人 y と人 x からなる二人組は区別しません。
制約
- 2 \leq N \leq 50
- 1 \leq M \leq 50
- 1 \leq a_{i,j} \leq N
- a_{i,1},\ldots,a_{i,N} には 1,\ldots,N が 1 回ずつ現れる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M
a_{1,1} \ldots a_{1,N}
\vdots
a_{M,1} \ldots a_{M,N}
出力
答えを出力せよ。
入力例 1
4 2 1 2 3 4 4 3 1 2
出力例 1
2
人 1 と人 4 からなる二人組と、人 2 と人 4 からなる二人組がそれぞれ不仲である可能性があります。
入力例 2
3 3 1 2 3 3 1 2 1 2 3
出力例 2
0
入力例 3
10 10 4 10 7 2 8 3 9 1 6 5 3 6 2 9 1 8 10 7 4 5 9 3 4 5 7 10 1 8 2 6 7 3 1 8 4 9 5 6 2 10 5 2 1 4 10 7 9 8 3 6 5 8 1 6 9 3 2 4 7 10 8 10 3 4 5 7 2 9 6 1 3 10 2 7 8 5 1 4 9 6 10 6 1 5 4 2 3 8 9 7 4 5 9 1 8 2 7 6 3 10
出力例 3
6
Score : 200 points
Problem Statement
N people numbered 1,2,\ldots,N were in M photos. In each of the photos, they stood in a single line. In the i-th photo, the j-th person from the left is person a_{i,j}.
Two people who did not stand next to each other in any of the photos may be in a bad mood.
How many pairs of people may be in a bad mood? Here, we do not distinguish a pair of person x and person y, and a pair of person y and person x.
Constraints
- 2 \leq N \leq 50
- 1 \leq M \leq 50
- 1 \leq a_{i,j} \leq N
- a_{i,1},\ldots,a_{i,N} contain each of 1,\ldots,N exactly once.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M
a_{1,1} \ldots a_{1,N}
\vdots
a_{M,1} \ldots a_{M,N}
Output
Print the answer.
Sample Input 1
4 2 1 2 3 4 4 3 1 2
Sample Output 1
2
The pair of person 1 and person 4, and the pair of person 2 and person 4, may be in a bad mood.
Sample Input 2
3 3 1 2 3 3 1 2 1 2 3
Sample Output 2
0
Sample Input 3
10 10 4 10 7 2 8 3 9 1 6 5 3 6 2 9 1 8 10 7 4 5 9 3 4 5 7 10 1 8 2 6 7 3 1 8 4 9 5 6 2 10 5 2 1 4 10 7 9 8 3 6 5 8 1 6 9 3 2 4 7 10 8 10 3 4 5 7 2 9 6 1 3 10 2 7 8 5 1 4 9 6 10 6 1 5 4 2 3 8 9 7 4 5 9 1 8 2 7 6 3 10
Sample Output 3
6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
あなたはアメーバの観察記録をつけました。
最初 1 匹のアメーバがおり、番号は 1 です。
観察記録は時系列順に N 個あり、i 番目の観察記録は「番号 A_i のアメーバが分裂して消滅し、新たに 2 匹のアメーバが生まれ、それらにそれぞれ 2i,2i+1 と番号をつけた」というものです。
このとき、アメーバ A_i を アメーバ 2i,2i+1 の親と呼びます。
各 k=1,\ldots,2N+1 について、アメーバ k から何代親を遡るとアメーバ 1 になるか求めてください。
制約
- 1 \leq N \leq 2\times 10^5
- 観察記録は矛盾していない。すなわち
- 1\leq A_i \leq 2i-1
- A_i は相異なる整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
2N+1 行出力せよ。k 行目にはアメーバ k から何代親を遡るとアメーバ 1 になるかを出力せよ。
入力例 1
2 1 2
出力例 1
0 1 1 2 2
アメーバ 1 からアメーバ 2,3 が生まれ、アメーバ 2 からアメーバ 4,5 が生まれました。
- アメーバ 1 は 0 代遡るとアメーバ 1 になります。
- アメーバ 2 は 1 代遡るとアメーバ 1 になります。
- アメーバ 3 は 1 代遡るとアメーバ 1 になります。
- アメーバ 4 は 1 代遡るとアメーバ 2 になり、2 代遡るとアメーバ 1 になります。
- アメーバ 5 は 1 代遡るとアメーバ 2 になり、2 代遡るとアメーバ 1 になります。
入力例 2
4 1 3 5 2
出力例 2
0 1 1 2 2 3 3 2 2
Score : 300 points
Problem Statement
You observed amoebae and kept some records.
Initially, there was one amoeba, numbered 1.
You made N records. According to the i-th record, the amoeba numbered A_i disappeared by dividing itself into two new amoebae, which were then numbered 2i and 2i+1.
Here, amoeba A_i is said to be the parent of amoebae 2i and 2i+1.
For each k=1,\ldots,2N+1, how many generations away is amoeba k from amoeba 1?
Constraints
- 1 \leq N \leq 2\times 10^5
- The records are consistent. That is:
- 1\leq A_i \leq 2i-1.
- A_i are distinct integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print 2N+1 lines. The k-th line should contain the generation distance between amoeba 1 and amoeba k.
Sample Input 1
2 1 2
Sample Output 1
0 1 1 2 2
From amoeba 1, amoebae 2 and 3 were born. From amoeba 2, amoebae 4 and 5 were born.
- Amoeba 1 is zero generations away from amoeba 1.
- Amoeba 2 is one generation away from amoeba 1.
- Amoeba 3 is one generation away from amoeba 1.
- Amoeba 4 is one generation away from amoeba 2, and two generations away from amoeba 1.
- Amoeba 5 is one generation away from amoeba 2, and two generations away from amoeba 1.
Sample Input 2
4 1 3 5 2
Sample Output 2
0 1 1 2 2 3 3 2 2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
AtCoder 社はロゴ入りの T シャツを販売しています。
高橋君の N 日間の予定が 0, 1, 2 のみからなる長さ N の文字列 S で与えられます。
具体的には、1\leq i\leq N をみたす整数 i について、
- S の i 文字目が
0のとき、i 日目に何の予定も入っていません。 - S の i 文字目が
1のとき、i 日目に高橋君は食事に行く予定があります。 - S の i 文字目が
2のとき、i 日目に高橋君は競技プログラミングのイベントに行く予定が入っています。
高橋君は無地の T シャツを M 枚持っており、1 日目の直前の時点ですべて洗濯済みの状態となっています。
これに加えて、次の条件をみたすように行動できるように、高橋君は AtCoder のロゴ入りの T シャツを何枚か購入する事にしました。
- 食事に行く日には、無地の T シャツ 1 枚またはロゴ入りの T シャツ 1 枚を着用する。
- 競技プログラミングのイベントに行く日にはロゴ入りの T シャツ 1 枚を着用する。
- 何の予定もない日には T シャツを着用しない。加えて、その時点で着用済みの T シャツを全て洗濯する。 洗濯した T シャツは翌日から着用できる。
- 一度着用した T シャツは次に洗濯するまで着用できない。
N 日間のうち予定が入っている日すべてについて、条件をみたす T シャツを着用できるようにするために、高橋君は最低何枚のTシャツを購入する必要があるか求めてください。
新しく T シャツを購入する必要がないならば 0 を出力してください。
ただし、購入した T シャツも 1 日目の直前の時点ですべて洗濯済みの状態で存在するものとします。
制約
- 1\leq M\leq N\leq 1000
- S は
0,1,2のみからなる長さ N の文字列 - N,M は整数
入力
入力は以下の形式で標準入力から与えられる。
N M S
出力
問題文の条件をみたすように行動するために
高橋君が購入する必要のある T シャツの枚数の最小値を出力せよ。
新しく購入する必要がないならば 0 を出力せよ。
入力例 1
6 1 112022
出力例 1
2
高橋君がロゴ入りの T シャツを 2 枚購入したとき、次のようにして高橋君は T シャツを着用することができます。
- 1 日目、高橋君はロゴ入りの T シャツを着用して食事に行きます。
- 2 日目、高橋君は無地の T シャツを着用して食事に行きます。
- 3 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。
- 4 日目、高橋君は予定がないため、着用した T シャツをすべて洗濯します。これにより、1,2,3 日目に着用した T シャツを再び着用することが可能になります。
- 5 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。
- 6 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。
高橋君がロゴ入りの T シャツを 1 枚以下しか購入しなかった場合には、
どのようにしても条件をみたすように T シャツを着用することができません。
よって、2 を出力します。
入力例 2
3 1 222
出力例 2
3
入力例 3
2 1 01
出力例 3
0
高橋君は新しく T シャツを購入する必要はありません。
Score : 300 points
Problem Statement
AtCoder Inc. sells T-shirts with its logo.
You are given Takahashi's schedule for N days as a string S of length N consisting of 0, 1, and 2.
Specifically, for an integer i satisfying 1\leq i\leq N,
- if the i-th character of S is
0, he has no plan scheduled for the i-th day; - if the i-th character of S is
1, he plans to go out for a meal on the i-th day; - if the i-th character of S is
2, he plans to attend a competitive programming event on the i-th day.
Takahashi has M plain T-shirts, all washed and ready to wear just before the first day.
In addition, to be able to satisfy the following conditions, he will buy several AtCoder logo T-shirts.
- On days he goes out for a meal, he will wear a plain or logo T-shirt.
- On days he attends a competitive programming event, he will wear a logo T-shirt.
- On days with no plans, he will not wear any T-shirts. Also, he will wash all T-shirts worn at that point. He can wear them again from the next day onwards.
- Once he wears a T-shirt, he cannot wear it again until he washes it.
Determine the minimum number of T-shirts he needs to buy to be able to wear appropriate T-shirts on all scheduled days during the N days. If he does not need to buy new T-shirts, print 0.
Assume that the purchased T-shirts are also washed and ready to use just before the first day.
Constraints
- 1\leq M\leq N\leq 1000
- S is a string of length N consisting of
0,1, and2. - N and M are integers.
Input
The input is given from Standard Input in the following format:
N M S
Output
Print the minimum number of T-shirts Takahashi needs to buy to be able to satisfy the conditions in the problem statement.
If he does not need to buy new T-shirts, print 0.
Sample Input 1
6 1 112022
Sample Output 1
2
If Takahashi buys two logo T-shirts, he can wear T-shirts as follows:
- On the first day, he wears a logo T-shirt to go out for a meal.
- On the second day, he wears a plain T-shirt to go out for a meal.
- On the third day, he wears a logo T-shirt to attend a competitive programming event.
- On the fourth day, he has no plans, so he washes all the worn T-shirts. This allows him to reuse the T-shirts worn on the first, second, and third days.
- On the fifth day, he wears a logo T-shirt to attend a competitive programming event.
- On the sixth day, he wears a logo T-shirt to attend a competitive programming event.
If he buys one or fewer logo T-shirts, he cannot use T-shirts to meet the conditions no matter what. Hence, print 2.
Sample Input 2
3 1 222
Sample Output 2
3
Sample Input 3
2 1 01
Sample Output 3
0
He does not need to buy new T-shirts.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 425 点
問題文
H 行 W 列のマス目があります。マス目の上から i 番目、左から j 番目のマスをマス (i,j) と表記します。
マス (i,j) は S_{i,j} が . のとき空きマスであり、# のとき障害物があります。
ある空きマスを出発し、上下左右に隣接するマスへの移動を K 回行う方法であって、障害物のあるマスを通らず、同じマスを 2 回以上通らないようなものの個数を数えてください。
具体的には、長さ K+1 の列 ((i_0,j_0),(i_1,j_1),\dots,(i_K,j_K)) であって、以下を満たすものの個数を数えてください。
- 各 0 \leq k \leq K について、 1 \leq i_k \leq H, 1 \leq j_k \leq W かつ S_{i_k,j_k} は
.である - 各 0 \leq k \leq K-1 について、 |i_{k+1}-i_k| + |j_{k+1}-j_k| = 1
- 各 0 \leq k < l \leq K について、 (i_k,j_k)\neq (i_l,j_l) である
制約
- 1 \leq H,W \leq 10
- 1 \leq K \leq 11
- H,W,K は整数
- S_{i,j} は
.または# - 空きマスが少なくとも 1 つ存在する
入力
入力は以下の形式で標準入力から与えられる。
H W K
S_{1,1}S_{1,2}\dots S_{1,W}
S_{2,1}S_{2,2}\dots S_{2,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}
出力
答えを出力せよ。
入力例 1
2 2 2 .# ..
出力例 1
2
可能な経路は、以下の 2 通りです。
- (1,1) \to (2,1) \to (2,2)
- (2,2) \to (2,1) \to (1,1)
入力例 2
2 3 1 .#. #.#
出力例 2
0
入力例 3
10 10 11 ....#..#.. .#.....##. ..#...##.. ...#...... ......##.. ..#......# #........# ..##...... .###....#. ...#.....#
出力例 3
218070
Score : 425 points
Problem Statement
There is a grid of H \times W cells. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left.
Cell (i, j) is empty if S_{i,j} is ., and blocked if it is #.
Count the number of ways to start from an empty cell and make K moves to adjacent cells (up, down, left, or right), without passing through blocked squares and not visiting the same cell more than once.
Specifically, count the number of sequences of length K+1, ((i_0, j_0), (i_1, j_1), \dots, (i_K, j_K)), satisfying the following.
- 1 \leq i_k \leq H, 1 \leq j_k \leq W, and S_{i_k, j_k} is
., for each 0 \leq k \leq K. - |i_{k+1} - i_k| + |j_{k+1} - j_k| = 1 for each 0 \leq k \leq K-1.
- (i_k, j_k) \neq (i_l, j_l) for each 0 \leq k < l \leq K.
Constraints
- 1 \leq H, W \leq 10
- 1 \leq K \leq 11
- H, W, and K are integers.
- Each S_{i,j} is
.or#. - There is at least one empty cell.
Input
The input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}\dots S_{1,W}
S_{2,1}S_{2,2}\dots S_{2,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}
Output
Print the answer.
Sample Input 1
2 2 2 .# ..
Sample Output 1
2
Here are the two possible paths:
- (1,1) \rightarrow (2,1) \rightarrow (2,2)
- (2,2) \rightarrow (2,1) \rightarrow (1,1)
Sample Input 2
2 3 1 .#. #.#
Sample Output 2
0
Sample Input 3
10 10 11 ....#..#.. .#.....##. ..#...##.. ...#...... ......##.. ..#......# #........# ..##...... .###....#. ...#.....#
Sample Output 3
218070
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 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
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
この問題は C 問題 (Operate 1) を完全に含んでおり、 K \le 20 です。
この問題に正解するコードを C 問題に提出することで、 C 問題に正解できます。
文字列 S に対して以下の操作を 0 回以上 K 回以下行って、文字列 T と一致させられるか判定してください。
- 次の 3 種類の操作のうちひとつを選択し、実行する。
- S 中の (先頭や末尾を含む) 任意の位置に、任意の文字を 1 つ挿入する。
- S 中の文字を 1 つ選び、削除する。
- S 中の文字を 1 つ選び、別の 1 つの文字に変更する。
制約
- S,T は英小文字からなる長さ 1 以上 500000 以下の文字列
- K は \color{red}{1 \le K \le 20} を満たす整数
入力
入力は以下の形式で標準入力から与えられる。
K S T
出力
K 回以下の操作で S を T に一致させられる時 Yes 、そうでない時 No と出力せよ。
入力例 1
3 abc awtf
出力例 1
Yes
例えば、次のように操作することで、 3 回の操作で abc を awtf に変換できます。
- 2 文字目の
bをwに変更する。操作後の文字列はawcとなる。 - 3 文字目の
cをfに変更する。操作後の文字列はawfとなる。 - 2 文字目と 3 文字目の間に
tを挿入する。操作後の文字列はawtfとなる。
入力例 2
2 abc awtf
出力例 2
No
2 回以下の操作では abc を awtf に変換できません。
入力例 3
17 twothousandtwentyfour happynewyear
出力例 3
Yes
Score : 525 points
Problem Statement
This problem fully contains Problem C (Operate 1), with K \le 20.
You can solve Problem C by submitting a correct solution to this problem for Problem C.
Determine whether it is possible to perform the following operation on string S between 0 and K times, inclusive, to make it identical to string T.
- Choose one of the following three operations and execute it.
- Insert any one character at any position in S (possibly the beginning or end).
- Delete one character from S.
- Choose one character in S and replace it with another character.
Constraints
- Each of S and T is a string of length between 1 and 500000, inclusive, consisting of lowercase English letters.
- K is an integer satisfying \color{red}{1 \le K \le 20}.
Input
The input is given from Standard Input in the following format:
K S T
Output
If S can be made identical to T with at most K operations, print Yes; otherwise, print No.
Sample Input 1
3 abc awtf
Sample Output 1
Yes
For example, here is a way to convert abc to awtf with three operations:
- Replace the second character
bwithw. After the operation, the string becomesawc. - Replace the third character
cwithf. After the operation, the string becomesawf. - Insert
tbetween the second and third characters. After the operation, the string becomesawtf.
Sample Input 2
2 abc awtf
Sample Output 2
No
abc cannot be converted to awtf with two or fewer operations.
Sample Input 3
17 twothousandtwentyfour happynewyear
Sample Output 3
Yes