実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
以下のような、1 から 9 までの数字が書かれた 3 \times 3 の盤面があります。

1 以上 9 以下の整数 A,B が与えられます。ただし、A < B です。
A が書かれたマスと B が書かれたマスが左右に隣接しているか判定してください。
制約
- 1 \le A < B \le 9
- A, B は整数である。
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
A が書かれたマスと B が書かれたマスが左右に隣接しているならば Yes、そうでないならば No を出力せよ。
入力例 1
7 8
出力例 1
Yes
7 が書かれたマスと 8 が書かれたマスは左右に隣り合っているので、Yes を出力します。
入力例 2
1 9
出力例 2
No
入力例 3
3 4
出力例 3
No
Score : 100 points
Problem Statement
We have the following 3 \times 3 board with integers from 1 through 9 written on it.

You are given two integers A and B between 1 and 9, where A < B.
Determine if the two squares with A and B written on them are adjacent horizontally.
Constraints
- 1 \le A < B \le 9
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print Yes if the two squares with A and B written on them are adjacent horizontally, and No otherwise.
Sample Input 1
7 8
Sample Output 1
Yes
The two squares with 7 and 8 written on them are adjacent horizontally, so print Yes.
Sample Input 2
1 9
Sample Output 2
No
Sample Input 3
3 4
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
AtCoder 王国の住民は A 時になるとたこ焼きへの愛を叫ぶことになっています。
AtCoder 王国に住む高橋君は毎日 B 時に就寝し C 時に起床します。高橋君は、起きているときはたこ焼きへの愛を叫ぶことができ、寝ているときは叫ぶことができません。高橋君が毎日たこ焼きへの愛を叫ぶことができているか判定してください。ただし、一日は 24 時間であり、高橋君が寝ている時間は 24 時間未満であるとします。
制約
- 0\leq A,B,C\lt 24
- A,B,C は相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
高橋君が毎日たこ焼きへの愛を叫ぶことができているならば Yes を、そうでないならば No を出力せよ。
入力例 1
21 8 14
出力例 1
Yes
高橋君は毎日 8 時に就寝し 14 時に起床します。21 時には起きているため、高橋君は毎日たこ焼きへの愛を叫ぶことができます。よって Yes を出力します。
入力例 2
0 21 7
出力例 2
No
高橋君は毎日 21 時に就寝し 7 時に起床します。0 時には起きていないため、高橋君は毎日たこ焼きへの愛を叫ぶことができません。よって No を出力します。
入力例 3
10 7 17
出力例 3
No
Score : 150 points
Problem Statement
In the Kingdom of AtCoder, residents are required to shout their love for takoyaki at A o'clock every day.
Takahashi, who lives in the Kingdom of AtCoder, goes to bed at B o'clock and wakes up at C o'clock every day (in the 24-hour clock). He can shout his love for takoyaki when he is awake, but cannot when he is asleep. Determine whether he can shout his love for takoyaki every day. Here, a day has 24 hours, and his sleeping time is less than 24 hours.
Constraints
- 0\leq A,B,C\lt 24
- A, B, and C are pairwise different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B C
Output
Print Yes if Takahashi can shout his love for takoyaki every day, and No otherwise.
Sample Input 1
21 8 14
Sample Output 1
Yes
Takahashi goes to bed at 8 o'clock and wakes up at 14 o'clock every day. He is awake at 21 o'clock, so he can shout his love for takoyaki every day. Therefore, print Yes.
Sample Input 2
0 21 7
Sample Output 2
No
Takahashi goes to bed at 21 o'clock and wakes up at 7 o'clock every day. He is not awake at 0 o'clock, so he cannot shout his love for takoyaki every day. Therefore, print No.
Sample Input 3
10 7 17
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
1 から N までの番号がつけられた N 個の国があり、i = 1, 2, \ldots, N について、高橋君は国 i の通貨を A_i 単位持っています。
高橋君は、下記の操作を好きな回数( 0 回でも良い)繰り返します。
- まず、1 以上 N-1 以下の整数 i を選ぶ。
- その後、国 i の通貨を S_i 単位以上持っているなら、下記の行動を 1 回行う。
- 国 i の通貨を S_i 単位だけ支払い、国 (i+1) の通貨を T_i 単位だけ獲得する。
最終的に高橋君が持っている国 N の通貨の単位数としてあり得る最大値を出力してください。
制約
- 入力される値はすべて整数
- 2 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- 1 \leq T_i \leq S_i \leq 10^9
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \ldots A_N
S_1 T_1
S_2 T_2
\vdots
S_{N-1} T_{N-1}
出力
答えを出力せよ。
入力例 1
4 5 7 0 3 2 2 4 3 5 2
出力例 1
5
以下の説明では、高橋君が持っている各国の通貨の単位数を、数列 A = (A_1, A_2, A_3, A_4) として表します。はじめ、A = (5, 7, 0, 3) です。
下記の通りに 4 回操作を行うことを考えます。
- i = 2 を選び、国 2 の通貨 4 単位を支払って、国 3 の通貨 3 単位を獲得する。その結果、A = (5, 3, 3, 3) となる。
- i = 1 を選び、国 1 の通貨 2 単位を支払って、国 2 の通貨 2 単位を獲得する。その結果、A = (3, 5, 3, 3) となる。
- i = 2 を選び、国 2 の通貨 4 単位を支払って、国 3 の通貨 3 単位を獲得する。その結果、A = (3, 1, 6, 3) となる。
- i = 3 を選び、国 3 の通貨 5 単位を支払って、国 4 の通貨 2 単位を獲得する。その結果、A = (3, 1, 1, 5) となる。
このとき、最終的に高橋君が持っている国 4 の通貨の単位数は 5 であり、これが考えられる最大値です。
入力例 2
10 32 6 46 9 37 8 33 14 31 5 5 5 3 1 4 3 2 2 3 2 3 2 4 4 3 3 3 1
出力例 2
45
Score: 150 points
Problem Statement
There are N countries numbered 1 to N. For each i = 1, 2, \ldots, N, Takahashi has A_i units of the currency of country i.
Takahashi can repeat the following operation any number of times, possibly zero:
- First, choose an integer i between 1 and N-1, inclusive.
- Then, if Takahashi has at least S_i units of the currency of country i, he performs the following action once:
- Pay S_i units of the currency of country i and gain T_i units of the currency of country (i+1).
Print the maximum possible number of units of the currency of country N that Takahashi could have in the end.
Constraints
- All input values are integers.
- 2 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- 1 \leq T_i \leq S_i \leq 10^9
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
S_1 T_1
S_2 T_2
\vdots
S_{N-1} T_{N-1}
Output
Print the answer.
Sample Input 1
4 5 7 0 3 2 2 4 3 5 2
Sample Output 1
5
In the following explanation, let the sequence A = (A_1, A_2, A_3, A_4) represent the numbers of units of the currencies of the countries Takahashi has. Initially, A = (5, 7, 0, 3).
Consider performing the operation four times as follows:
- Choose i = 2, pay four units of the currency of country 2, and gain three units of the currency of country 3. Now, A = (5, 3, 3, 3).
- Choose i = 1, pay two units of the currency of country 1, and gain two units of the currency of country 2. Now, A = (3, 5, 3, 3).
- Choose i = 2, pay four units of the currency of country 2, and gain three units of the currency of country 3. Now, A = (3, 1, 6, 3).
- Choose i = 3, pay five units of the currency of country 3, and gain two units of the currency of country 4. Now, A = (3, 1, 1, 5).
At this point, Takahashi has five units of the currency of country 4, which is the maximum possible number.
Sample Input 2
10 32 6 46 9 37 8 33 14 31 5 5 5 3 1 4 3 2 2 3 2 3 2 4 4 3 3 3 1
Sample Output 2
45
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる長さ 3 以上の文字列 S が与えられます。
S はちょうど 2 種類の文字を含み、 1 文字だけ他の文字と異なります。その 1 文字を答えてください。
例えば、 S が odd なら o と答えてください。
制約
- S は英小文字からなる長さ 3 以上 10 以下の文字列
- S はちょうど 2 種類の文字を含み、 1 文字だけ他の文字と異なる
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
odd
出力例 1
o
odd のうち他の文字と異なるものは o です。
入力例 2
dad
出力例 2
a
dad のうち他の文字と異なるものは a です。
入力例 3
wwwwwwwwwv
出力例 3
v
wwwwwwwwwv のうち他の文字と異なるものは v です。
Score : 200 points
Problem Statement
You are given a string S of length at least 3 consisting of lowercase English letters.
S contains exactly two types of characters, and exactly one character is different from the others. Find that one character.
For example, if S is odd, report o.
Constraints
- S is a string of length at least 3 and at most 10 consisting of lowercase English letters.
- S contains exactly two types of characters, and exactly one character is different from the others.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
odd
Sample Output 1
o
In odd, the character different from the others is o.
Sample Input 2
dad
Sample Output 2
a
In dad, the character different from the others is a.
Sample Input 3
wwwwwwwwwv
Sample Output 3
v
In wwwwwwwwwv, the character different from the others is v.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君は英小文字からなる文字列 T を青木君に向けて送りました。その結果、青木君は英小文字からなる文字列 T' を受信しました。
T' は T から一部が変更されてしまっている可能性があり、具体的には、下記の 4 つのうちのちょうど 1 つが成り立つことがわかっています。
- T' は、T と等しい。
- T' は、T のいずれか 1 つの位置(先頭と末尾も含む)に英小文字を 1 つ挿入して得られる文字列である。
- T' は、T からある 1 文字を削除して得られる文字列である。
- T' は、T のある 1 文字を別の英小文字に変更して得られる文字列である。
青木君が受信した文字列 T' と、英小文字からなる N 個の文字列 S_1, S_2, \ldots, S_N が入力として与えられるので、 S_1, S_2, \ldots, S_N のうち、高橋君が送った文字列 T と等しい可能性があるものをすべて求めてください。
制約
- N は整数
- 1 \leq N \leq 5 \times 10^5
- S_i と T' は英小文字からなる長さ 1 以上 5 \times 10^5 以下の文字列
- S_1, S_2, \ldots, S_N の長さの総和は 5 \times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
N T' S_1 S_2 \vdots S_N
出力
S_1, S_2, \ldots, S_N のうち T と等しい可能性があるものすべての添字を昇順に並べた列を (i_1, i_2, \ldots, i_K) とする。 この列の長さ K および列自体を、下記の形式にしたがって出力せよ。
K i_1 i_2 \ldots i_K
入力例 1
5 ababc ababc babc abacbc abdbc abbac
出力例 1
4 1 2 3 4
S_1, S_2, \ldots, S_5 のうち、T と等しい可能性があるものは S_1, S_2, S_3, S_4 の 4 つであることが下記の通りわかります。
- S_1 は T と等しい可能性があります。なぜなら、T' =
ababcは S_1 =ababcと等しいからです。 - S_2 は T と等しい可能性があります。なぜなら、T' =
ababcは S_2 =babcの先頭に文字aを挿入して得られる文字列だからです。 - S_3 は T と等しい可能性があります。なぜなら、T' =
ababcは S_3 =abacbcから 4 文字目のcを削除して得られる文字列だからです。 - S_4 は T と等しい可能性があります。なぜなら、T' =
ababcは S_4 =abdbcの 3 文字目のdをbに変更して得られる文字列だからです。 - S_5 は T と等しい可能性はありません。なぜなら、S_5 =
abbacを T としたとき、T' =ababcは問題文中の 4 つの条件をいずれも満たさないからです。
入力例 2
1 aoki takahashi
出力例 2
0
入力例 3
9 atcoder atoder atcode athqcoder atcoder tacoder jttcoder atoder atceoder atcoer
出力例 3
6 1 2 4 7 8 9
Score : 300 points
Problem Statement
Takahashi sent a string T consisting of lowercase English letters to Aoki. As a result, Aoki received a string T' consisting of lowercase English letters.
T' may have been altered from T. Specifically, exactly one of the following four conditions is known to hold.
- T' is equal to T.
- T' is a string obtained by inserting one lowercase English letter at one position (possibly the beginning and end) in T.
- T' is a string obtained by deleting one character from T.
- T' is a string obtained by changing one character in T to another lowercase English letter.
You are given the string T' received by Aoki and N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters. Find all the strings among S_1, S_2, \ldots, S_N that could equal the string T sent by Takahashi.
Constraints
- N is an integer.
- 1 \leq N \leq 5 \times 10^5
- S_i and T' are strings of length between 1 and 5 \times 10^5, inclusive, consisting of lowercase English letters.
- The total length of S_1, S_2, \ldots, S_N is at most 5 \times 10^5.
Input
The input is given from Standard Input in the following format:
N T' S_1 S_2 \vdots S_N
Output
Let (i_1, i_2, \ldots, i_K) be the sequence of indices of all the strings among S_1, S_2, \ldots, S_N that could be equal to T, in ascending order. Print the length K of this sequence, and the sequence itself, in the following format:
K i_1 i_2 \ldots i_K
Sample Input 1
5 ababc ababc babc abacbc abdbc abbac
Sample Output 1
4 1 2 3 4
Among S_1, S_2, \ldots, S_5, the strings that could be equal to T are S_1, S_2, S_3, S_4, as explained below.
- S_1 could be equal to T, because T' =
ababcis equal to S_1 =ababc. - S_2 could be equal to T, because T' =
ababcis obtained by inserting the letteraat the beginning of S_2 =babc. - S_3 could be equal to T, because T' =
ababcis obtained by deleting the fourth charactercfrom S_3 =abacbc. - S_4 could be equal to T, because T' =
ababcis obtained by changing the third characterdin S_4 =abdbctob. - S_5 could not be equal to T, because if we take S_5 =
abbacas T, then T' =ababcdoes not satisfy any of the four conditions in the problem statement.
Sample Input 2
1 aoki takahashi
Sample Output 2
0
Sample Input 3
9 atcoder atoder atcode athqcoder atcoder tacoder jttcoder atoder atceoder atcoer
Sample Output 3
6 1 2 4 7 8 9