Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英大文字と英小文字からなる文字列 S が与えられます。S の英大文字のみを元の順序で連結して得られる文字列を出力してください。
制約
- S は英大文字と英小文字からなる文字列である
- S の長さは 1 以上 100 以下である
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の英大文字のみを元の順序で連結して得られる文字列を出力せよ。
入力例 1
AtCoderBeginnerContest
出力例 1
ACBC
S の英大文字のみを元の順序で連結して得られる文字列は ACBC です。よって、ACBC を出力します。
入力例 2
PaymentRequired
出力例 2
PR
入力例 3
program
出力例 3
S に英大文字が含まれないことがあることに注意してください。
Score : 100 points
Problem Statement
You are given a string S consisting of uppercase and lowercase English letters. Print the string obtained by concatenating only the uppercase letters of S in their original order.
Constraints
- S is a string of uppercase and lowercase English letters.
- The length of S is between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the string obtained by concatenating only the uppercase letters of S in their original order.
Sample Input 1
AtCoderBeginnerContest
Sample Output 1
ACBC
The string obtained by concatenating only the uppercase letters of S in their original order is ACBC. Hence, print ACBC.
Sample Input 2
PaymentRequired
Sample Output 2
PR
Sample Input 3
program
Sample Output 3
Note that S may contain no uppercase letters.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる長さ 1 以上 25 以下の文字列 S が与えられます。
S に含まれない英小文字をひとつ出力してください。
但し、そのようなものが複数ある場合はどれを出力しても構いません。
制約
- S は英小文字からなる長さ 1 以上 25 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S に含まれない英小文字をひとつ出力せよ。そのようなものが複数ある場合はどれを出力しても構わない。
入力例 1
a
出力例 1
d
S= a です。
a 以外の英小文字、 b, c, ..., z が正解となります。
入力例 2
abcdfhijklmnopqrstuvwxyz
出力例 2
e
S 中に含まれない英小文字は e と g です。
入力例 3
qazplwsxokmedcijnrfvuhbgt
出力例 3
y
Score : 100 points
Problem Statement
You are given a string S of length between 1 and 25 consisting of lowercase English letters.
Output one lowercase English letter that does not appear in S.
If there are multiple such letters, you may output any one of them.
Constraints
- S is a string of length between 1 and 25 (inclusive) consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Output one lowercase English letter that does not appear in S. If there are multiple such letters, you may output any one of them.
Sample Input 1
a
Sample Output 1
d
S= a.
Any lowercase English letter other than a (that is, b, c, …, or z) is a correct answer.
Sample Input 2
abcdfhijklmnopqrstuvwxyz
Sample Output 2
e
The lowercase English letters not included in S are e and g.
Sample Input 3
qazplwsxokmedcijnrfvuhbgt
Sample Output 3
y
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
数字のみからなる長さ 6 の文字列が N 個与えられます。i \, (i = 1, 2, \dots, N) 番目のものを S_i と表します。
さらに、数字のみからなる長さ 3 の文字列が M 個与えられます。j \, (j = 1, 2, \dots, M) 番目のものを T_j と表します。
S_1, S_2, \dots, S_N のうち、末尾 3 文字が T_1, T_2, \dots, T_M のいずれかに一致するものの個数を求めてください。
制約
- 1 \leq N, M \leq 1000
- N, M は整数
- 全ての i = 1, 2, \dots, N に対し、S_i は数字のみからなる長さ 6 の文字列
- 全ての j = 1, 2, \dots, M に対し、T_j は数字のみからなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
出力
答えを出力せよ。
入力例 1
3 3 142857 004159 071028 159 287 857
出力例 1
2
S_1 の末尾 3 文字は 857 であり、これは T_3 に一致します。
S_2 の末尾 3 文字は 159 であり、これは T_1 に一致します。
S_3 の末尾 3 文字は 028 であり、これは T_1, T_2, T_3 のいずれにも一致しません。
以上から、答えは 2 です。
入力例 2
5 4 235983 109467 823476 592801 000333 333 108 467 983
出力例 2
3
入力例 3
4 4 000000 123456 987111 000000 000 111 999 111
出力例 3
3
Score : 200 points
Problem Statement
You are given N strings of length six each, consisting of digits. Let S_i be the i-th (i = 1, 2, \dots, N) of them.
You are also given M strings of length three each, consisting of digits. Let T_j be the j-th (j = 1, 2, \dots, M) of them.
Find the number of strings among S_1, S_2, \dots, S_N whose last three characters coincide with one or more of T_1, T_2, \dots, T_M.
Constraints
- 1 \leq N, M \leq 1000
- N and M are integers.
- S_i is a string of length 6 consisting of digits, for all i = 1, 2, \dots, N.
- T_j is a string of length 3 consisting of digits, for all j = 1, 2, \dots, M.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
Output
Print the answer.
Sample Input 1
3 3 142857 004159 071028 159 287 857
Sample Output 1
2
The last three characters of S_1 are 857, which coincide with T_3.
The last three characters of S_2 are 159, which coincide with T_1.
The last three characters of S_3 are 028, which do not coincide with T_1, T_2, or T_3.
Thus, the answer is 2.
Sample Input 2
5 4 235983 109467 823476 592801 000333 333 108 467 983
Sample Output 2
3
Sample Input 3
4 4 000000 123456 987111 000000 000 111 999 111
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
人 1,2,\dots,N ( N は奇数 ) が、 M 回の 0 か 1 かを選択する投票を行いました。
各人の各回の投票は N 個の長さ M の 0, 1 からなる文字列 S_1,S_2,\dots,S_N として与えられ、 S_i の j 文字目は人 i の j 回目の投票への内容を表します。
各回の投票で、少数派であった人は 1 点を得ます。
より厳密には、次のルールで得点が与えられます。
- その回の投票で
0を選択した人が x 人、1を選択した人が y 人いたとします。- x=0 または y=0 である場合、その投票では全員に 1 点が与えられる。
- そうでなく x<y である場合、その投票で
0に投票した人のみに 1 点が与えられる。 - そうでない場合、その投票で
1に投票した人のみに 1 点が与えられる。 - なお、 N が奇数であることから x=y となることはないことに留意してください。
M 回の投票を終えた後、それらの投票における合計の得点が最も高い人を全員求めてください。
制約
- N は 1 \le N \le 99 を満たす 奇数
- M は 1 \le M \le 100 を満たす整数
- S_i は長さ M の
0,1からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
得点が最も高い人の番号を全て、 番号の昇順に 空白区切りで出力せよ。
入力例 1
3 5 11100 10101 01110
出力例 1
2 3
このケースでは、 3 人が 5 回の投票を行いました。
- 1 回目の投票では人 1 が
1、人 2 が1、人 3 が0に投票しました。よって、人 3 のみが 1 点を得ます。 - 2 回目の投票では人 1 が
1、人 2 が0、人 3 が1に投票しました。よって、人 2 のみが 1 点を得ます。 - 3 回目の投票では人 1 が
1、人 2 が1、人 3 が1に投票しました。よって、全員が 1 点を得ます。 - 4 回目の投票では人 1 が
0、人 2 が0、人 3 が1に投票しました。よって、人 3 のみが 1 点を得ます。 - 5 回目の投票では人 1 が
0、人 2 が1、人 3 が0に投票しました。よって、人 2 のみが 1 点を得ます。
この結果、人 1 は合計 1 点、人 2 は合計 3 点、人 3 は合計 3 点を得ました。
よって、人 2,3 が合計の得点が最も高い人です。これらを番号の昇順に出力してください。
入力例 2
5 4 0000 0000 0000 0000 0000
出力例 2
1 2 3 4 5
入力例 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
出力例 3
1 2 3
Score : 200 points
Problem Statement
People 1,2,\dots,N (where N is odd) conducted M votes where each person chooses either 0 or 1.
Each person's vote for each round is given as N strings S_1,S_2,\dots,S_N of length M consisting of 0 and 1, where the j-th character of S_i represents person i's vote content for the j-th vote.
In each vote, people who were in the minority receive 1 point.
More precisely, points are given according to the following rules:
- Suppose x people chose
0and y people chose1in that vote.- If x=0 or y=0, everyone receives 1 point for that vote.
- Otherwise, if x<y, only people who voted
0in that vote receive 1 point. - Otherwise, only people who voted
1in that vote receive 1 point. - Note that since N is odd, x=y never occurs.
After finishing M votes, find all people who have the highest total score from those votes.
Constraints
- N is an odd number satisfying 1 \le N \le 99.
- M is an integer satisfying 1 \le M \le 100.
- S_i is a string of length M consisting of
0and1.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Output all person numbers with the highest score in ascending order of person number, separated by spaces.
Sample Input 1
3 5 11100 10101 01110
Sample Output 1
2 3
In this case, three people conducted five votes.
- In the 1st vote, person 1 voted
1, person 2 voted1, person 3 voted0. Thus, only person 3 receives 1 point. - In the 2nd vote, person 1 voted
1, person 2 voted0, person 3 voted1. Thus, only person 2 receives 1 point. - In the 3rd vote, person 1 voted
1, person 2 voted1, person 3 voted1. Thus, everyone receives 1 point. - In the 4th vote, person 1 voted
0, person 2 voted0, person 3 voted1. Thus, only person 3 receives 1 point. - In the 5th vote, person 1 voted
0, person 2 voted1, person 3 voted0. Thus, only person 2 receives 1 point.
As a result, person 1 received a total of 1 points, person 2 received a total of 3 points, and person 3 received a total of 3 points.
Therefore, persons 2 and 3 have the highest total score. Output these in ascending order of person number.
Sample Input 2
5 4 0000 0000 0000 0000 0000
Sample Output 2
1 2 3 4 5
Sample Input 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
Sample Output 3
1 2 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は部屋に PC を沢山置こうとしています。そこで最大何台の PC を部屋に置けるか調べるプログラムを書くことにしました。
H 個の長さ W の ., T からなる文字列 S_1,S_2,\ldots,S_H が与えられます。
高橋君は以下の操作を 0 回以上何回でも行うことができます。
- 1\leq i \leq H, 1 \leq j \leq W-1 を満たす整数であって、 S_i の j 番目の文字も j+1 番目の文字も
Tであるようなものを選ぶ。 S_i の j 番目の文字をPで置き換え、S_i の j+1 番目の文字をCで置き換える。
高橋君が操作回数の最大化を目指すとき、操作終了後の S_1,S_2,\ldots,S_H としてあり得るものの一例を出力してください。
制約
- 1\leq H \leq 100
- 2\leq W \leq 100
- H と W は整数である
- S_i は
.,Tからなる長さ W の文字列
入力
入力は以下の形式で標準入力から与えられる。
H W S_1 S_2 \vdots S_H
出力
高橋君が操作回数の最大化を目指すとき、操作終了後の S_1,S_2,\ldots,S_H としてあり得るものの一例を改行区切りで出力せよ。
解が複数存在する場合、どれを出力しても正答とみなされる。
入力例 1
2 3 TTT T.T
出力例 1
PCT T.T
可能な操作回数の最大値は 1 です。
例えば、 (i,j)=(1,1) として操作を行うと、S_1 が PCT に変化します。
入力例 2
3 5 TTT.. .TTT. TTTTT
出力例 2
PCT.. .PCT. PCTPC
Score : 300 points
Problem Statement
Planning to place many PCs in his room, Takahashi has decided to write a code that finds how many PCs he can place in his room.
You are given H strings S_1,S_2,\ldots,S_H, each of length W, consisting of . and T.
Takahashi may perform the following operation any number of times (possibly zero):
- Choose integers satisfying 1\leq i \leq H and 1 \leq j \leq W-1 such that the j-th and (j+1)-th characters of S_i are both
T. Replace the j-th character of S_i withP, and (j+1)-th withC.
He tries to maximize the number of times he performs the operation. Find possible resulting S_1,S_2,\ldots,S_H.
Constraints
- 1\leq H \leq 100
- 2\leq W \leq 100
- H and W are integers.
- S_i is a string of length W consisting of
.andT.
Input
The input is given from Standard Input in the following format:
H W S_1 S_2 \vdots S_H
Output
Print a sequence of strings, S_1,S_2,\ldots,S_H, separated by newlines, possibly resulting from maximizing the number of times he performs the operation.
If multiple solutions exist, print any of them.
Sample Input 1
2 3 TTT T.T
Sample Output 1
PCT T.T
He can perform the operation at most once.
For example, an operation with (i,j)=(1,1) makes S_1 PCT.
Sample Input 2
3 5 TTT.. .TTT. TTTTT
Sample Output 2
PCT.. .PCT. PCTPC
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君と青木君は、それぞれ N 個のボールに M 本のひもを取り付けたおもちゃを持っています。
高橋君のおもちゃにおいて、ボールには 1, \dots, N と番号が付けられており、i \, (1 \leq i \leq M) 本目のひもはボール A_i とボール B_i を結んでいます。
青木君のおもちゃにおいても同様に、ボールには 1, \dots, N と番号が付けられており、i \, (1 \leq i \leq M) 本目のひもはボール C_i とボール D_i を結んでいます。
それぞれのおもちゃにおいて、同一のボールを結ぶようなひもは存在せず、2 つのボールを 2 本以上の異なるひもが結んでいることはありません。
すぬけ君は、2 人のおもちゃが同じ形であるかどうか気になっています。
ここで、2 人のおもちゃが同じ形であるとは、以下の条件を満たす数列 P が存在することをいいます。
- P は (1, \dots, N) を並べ替えて得られる。
- 任意の 1 以上 N 以下の整数 i, j に対し、以下が成り立つ。
- 高橋君のおもちゃにおいてボール i, j がひもで繋がれていることと、青木君のおもちゃにおいてボール P_i, P_j がひもで繋がれていることは同値である。
2 人のおもちゃが同じ形であるなら Yes、そうでないなら No と出力してください。
制約
- 1 \leq N \leq 8
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
- (A_i, B_i) \neq (A_j, B_j) \, (i \neq j)
- 1 \leq C_i \lt D_i \leq N \, (1 \leq i \leq M)
- (C_i, D_i) \neq (C_j, D_j) \, (i \neq j)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 \vdots A_M B_M C_1 D_1 \vdots C_M D_M
出力
2 人のおもちゃが同じ形であるなら Yes、そうでないなら No と出力せよ。
入力例 1
4 4 1 2 1 3 1 4 3 4 1 3 1 4 2 3 3 4
出力例 1
Yes
高橋君のおもちゃは下図の左側のような形をしており、青木君のおもちゃは下図の右側のような形をしています。

次の図から、2 人のおもちゃが同じ形であることがわかります。例えば P = (3, 2, 1, 4) とすると問題文中の条件を満たします。

入力例 2
5 6 1 2 1 3 1 4 3 4 3 5 4 5 1 2 1 3 1 4 1 5 3 5 4 5
出力例 2
No
2 人のおもちゃは同じ形ではありません。

入力例 3
8 0
出力例 3
Yes
Score : 300 points
Problem Statement
Takahashi and Aoki each have a toy made by attaching M cords to N balls.
In Takahashi's toy, the balls are numbered 1, \dots, N, and the i-th cord ties Ball A_i and B_i.
Similarly, in Aoki's toy, the balls are numbered 1, \dots, N, and the i-th cord ties Ball C_i and D_i.
In each toy, no cord ties a ball to itself, and no two balls are tied by two or more different cords.
Snuke is wondering whether the two toys have the same shape.
Here, they are said to have the same shape when there is a sequence P that satisfies the conditions below.
- P is a permutation of (1, \dots, N).
- For every pair of integers i, j between 1 and N (inclusive), the following holds.
- Balls i and j in Takahashi's toy are tied by a cord if and only if Balls P_i and P_j in Aoki's toy are tied by a cord.
If the two toys have the same shape, print Yes; otherwise, print No.
Constraints
- 1 \leq N \leq 8
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
- (A_i, B_i) \neq (A_j, B_j) \, (i \neq j)
- 1 \leq C_i \lt D_i \leq N \, (1 \leq i \leq M)
- (C_i, D_i) \neq (C_j, D_j) \, (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 B_1 \vdots A_M B_M C_1 D_1 \vdots C_M D_M
Output
If the two toys have the same shape, print Yes; otherwise, print No.
Sample Input 1
4 4 1 2 1 3 1 4 3 4 1 3 1 4 2 3 3 4
Sample Output 1
Yes
Takahashi's toy is illustrated on the left in the figure below, and Aoki's is illustrated on the right.

The following figure shows that the two toys have the same shape. The condition in the statement is satisfied when P = (3, 2, 1, 4), for example.

Sample Input 2
5 6 1 2 1 3 1 4 3 4 3 5 4 5 1 2 1 3 1 4 1 5 3 5 4 5
Sample Output 2
No
The two toys do not have the same shape.

Sample Input 3
8 0
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
この問題は インタラクティブな問題(あなたの作成したプログラムとジャッジシステムが入出力を介して対話を行う形式の問題)です。
整数 N および N 未満の 奇数 K が与えられます。
ジャッジシステムは、0 および 1 からなる長さ N の数列 A = (A_1, A_2, \dots, A_N) を隠し持っています。
あなたは数列 A の要素の値を直接知ることはできません。
その代わりに、ジャッジシステムに対して以下の質問を N 回まで行うことができます。
- 1 以上 N 以下の相異なる整数 x_1, x_2, \dots, x_K を選ぶ。そして、A_{x_1} + A_{x_2} + \dots + A_{x_K} の偶奇を聞く。
N 回以下の質問で (A_1, A_2, \dots, A_N) を全て特定して、答えを出力してください。
ただし、ジャッジは適応的です。言い換えると、ジャッジシステムは今までの質問の回答に矛盾しない範囲でA の内容を自由に変更することができます。
そのため、出力が次の条件を満たす場合にあなたの作成したプログラムは正解とみなされます。それ以外の場合は不正解とみなされます。
- ここまでの質問の回答と矛盾しないような数列が一意に定まっており、かつそれがプログラムが出力した数列と一致している。
制約
- 1 \leq K \lt N \leq 1000
- K は奇数
- A_i は 0 または 1
入出力
この問題はインタラクティブな問題(あなたの作成したプログラムとジャッジシステムが入出力を介して対話を行う形式の問題)です。
最初に、N および K を標準入力から受け取ってください。
N K
次に、(A_1, A_2, \dots, A_N) を全て特定できるまで質問を繰り返してください。
質問は、以下の形式で標準出力に出力してください。ここで x_1, x_2, \dots, x_K は 1 以上 N 以下の相異なる K 個の整数です。
? x_1 x_2 \dots x_K
これに対する応答は、次の形式で標準入力から与えられます。
T
ここで、T は質問に対する答えで、
- T が
0である場合は A_{x_1} + A_{x_2} + \dots + A_{x_K} は偶数であることを、 - T が
1である場合は A_{x_1} + A_{x_2} + \dots + A_{x_K} は奇数であることを意味します。
ただし、x_1, x_2, \dots, x_K が制約を満たしていないか、質問の回数が N 回を超えた場合は T は -1 となります。
ジャッジが -1 を返した場合、プログラムはすでに不正解とみなされています。この場合、ただちにプログラムを終了してください。
A の要素を全て特定できたら、特定した A の要素を以下の形式で出力してください。その後、ただちにプログラムを終了してください。
! A_1 A_2 \dots A_N
注意点
- 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 対話の途中で誤った出力形式による出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
- 解答を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
- ジャッジは適応的です。言い換えると、ジャッジシステムは今までの質問の回答に矛盾しない範囲で A の内容を変更することができます。
入出力例
以下の入出力例は N=5, K=3 の場合の入出力例です。この入出力例の通りに出力するとジャッジ結果は WA になることに注意してください。
入出力例では、プログラムが出力した A = (1, 0, 1, 1, 0) はここまでの質問の回答に矛盾しない数列ですが、例えば (0, 0, 1, 0, 0) もここまでの質問の回答に矛盾しない数列であるため、数列 A は一意に定まっていません。そのため、このプログラムは不正解とみなされます。
| 入力 | 出力 | 説明 |
|---|---|---|
5 3 | まず整数 N および K が与えられます。 | |
? 2 4 1 | (x_1, x_2, x_3) = (2, 4, 1) として質問を行います。 | |
0 | 質問の答えは 0 なので、ジャッジはその値を返します。 | |
? 5 3 2 | (x_1, x_2, x_3) = (5, 3, 2) として質問を行います。 | |
1 | 質問の答えは 1 なので、ジャッジはその値を返します。 | |
! 1 0 1 1 0 | A の答えとして (1, 0, 1, 1, 0) を出力します。A を一意に特定できていないのでジャッジ結果は WA になります。 |
Score : 550 points
Problem Statement
This is an interactive task (where your program and the judge interact via Standard Input and Output).
You are given an integer N and an odd number K.
The judge has a hidden length-N sequence A = (A_1, A_2, \dots, A_N) consisting of 0 and 1.
While you cannot directly access the elements of sequence A, you are allowed to ask the judge the following query at most N times.
- Choose distinct integers x_1, x_2, \dots, and x_K between 1 and N, inclusive, to ask the parity of A_{x_1} + A_{x_2} + \dots + A_{x_K}.
Determine (A_1, A_2, \dots, A_N) by at most N queries, and print the answer.
Here, the judge is adaptive. In other words, the judge may modify the contents of A as long as it is consistent with the responses to the past queries.
Therefore, your program is considered correct if the output satisfies the following condition, and incorrect otherwise:
- your program prints a sequence consistent with the responses to the queries so far, and that is the only such sequence.
Constraints
- 1 \leq K \lt N \leq 1000
- K is odd.
- A_i is 0 or 1.
Input and Output
This is an interactive task (where your program and the judge interact via Standard Input and Output).
First of all, receive N and K from Standard Input.
N K
Then, repeat asking queries until you can uniquely determine (A_1, A_2, \dots, A_N).
Each query should be printed to Standard Output in the following format, where x_1, x_2, \dots, and x_K are K distinct integers between 1 and N, inclusive.
? x_1 x_2 \dots x_K
The response to the query is given from Standard Input in the following format.
T
Here, T denotes the response to the query.
- T is
0when A_{x_1} + A_{x_2} + \dots + A_{x_K} is even, and - T is
1when A_{x_1} + A_{x_2} + \dots + A_{x_K} is odd.
However, if x_1, x_2, \dots and x_K do not satisfy the constraints, or the number of queries exceeds N, then T is -1.
If the judge returns -1, your program is already considered incorrect, so terminate the program immediately.
When you can determine all the elements of A, print those elements in the following format, and terminate the program immediately.
! A_1 A_2 \dots A_N
Notes
- Print a newline and flush Standard Output at the end of each message. Otherwise, you may get a TLE verdict.
- The verdict will be indeterminate if there is malformed output during the interaction or your program quits prematurely.
- Terminate the program immediately after printing the answer, or the verdict will be indeterminate.
- The judge for this problem is adaptive. This means that the judge may modify the contents of A as long as it is consistent with the responses to the past queries.
Sample Interaction
In the following interaction, N=5 and K=3. Note that the following output itself will result in WA.
Here, A = (1, 0, 1, 1, 0) is indeed consistent with the responses, but so is (0, 0, 1, 0, 0), so sequence A is not uniquely determined. Thus, this program is considered incorrect.
| Input | Output | Description |
|---|---|---|
5 3 | First, you are given integers N and K. | |
? 2 4 1 | You ask a query with (x_1, x_2, x_3) = (2, 4, 1). | |
0 | The response to the query is 0, so the judge returns that value. | |
? 5 3 2 | You ask a query with (x_1, x_2, x_3) = (5, 3, 2). | |
1 | The response to the query is 1, so the judge returns that value. | |
! 1 0 1 1 0 | You print (1, 0, 1, 1, 0) to guess A. Since sequence A is not uniquely determined, the verdict will be WA. |
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
H 行 W 列の格子状の区画に区切られた街があります。上から i 行目、左から j 列目の区画は、S_{i,j} が . のとき道、# のとき塀です。
高橋君は自分の家から魚屋に買い物に行くことにしました。高橋君の家は街の左上隅の区画にあり、魚屋は街の右下隅の区画にあります。
高橋君は、自分がいる区画から上下左右に隣接する道の区画に移動することができます。街の外に出ることはできません。
塀の区画に移動することはできませんが、高橋君は非常に腕力が強いため、パンチを 1 回繰り出すことで任意の 2\times 2 の区画内の塀を壊して道にすることができます。
高橋君が魚屋にたどり着くためには、最低何回パンチを繰り出せばよいか求めてください。
制約
- 2 \leq H,W \leq 500
- H,W は整数
- S_{i,j} は
.または# - S_{1,1} と S_{H,W} は
.
入力
入力は以下の形式で標準入力から与えられる。
H W
S_{1,1} \ldots S_{1,W}
\vdots
S_{H,1} \ldots S_{H,W}
出力
答えを出力せよ。
入力例 1
5 5 ..#.. #.#.# ##.## #.#.# ..#..
出力例 1
1
例えば、以下の * で表す 2\times 2 の区画にある塀を破壊すると魚屋にたどり着くことができます。
..#.. #.**# ##**# #.#.# ..#..
破壊対象の 2 \times 2 の区画の全てが塀である必要はありません。
入力例 2
5 7 ....... ######. ....... .###### .......
出力例 2
0
遠回りが必要ですが、塀を破壊することなく魚屋にたどり着くことができます。
入力例 3
8 8 .####### ######## ######## ######## ######## ######## ######## #######.
出力例 3
5
Score : 500 points
Problem Statement
There is a town divided into a grid of cells with H rows and W columns. The cell at the i-th row from the top and j-th column from the left is a passable space if S_{i,j} is . and a block if S_{i,j} is #.
Takahashi will go from his house to a fish market. His house is in the cell at the top-left corner, and the fish market is in the cell at the bottom-right corner.
Takahashi can move one cell up, down, left, or right to a passable cell. He cannot leave the town. He cannot enter a block, either. However, his physical strength allows him to destroy all blocks in a square region with 2\times 2 cells of his choice with one punch, making these cells passable.
Find the minimum number of punches needed for Takahashi to reach the fish market.
Constraints
- 2 \leq H,W \leq 500
- H and W are integers.
- S_{i,j} is
.or#. - S_{1,1} and S_{H,W} are
..
Input
Input is given from Standard Input in the following format:
H W
S_{1,1} \ldots S_{1,W}
\vdots
S_{H,1} \ldots S_{H,W}
Output
Print the answer.
Sample Input 1
5 5 ..#.. #.#.# ##.## #.#.# ..#..
Sample Output 1
1
He can reach the fish market by, for example, destroying the blocks in the square region with 2\times 2 cells marked * below.
..#.. #.**# ##**# #.#.# ..#..
It is not required that all of the 2\times 2 cells in the region to punch are blocks.
Sample Input 2
5 7 ....... ######. ....... .###### .......
Sample Output 2
0
He can reach the fish market without destroying blocks, though he has to go a long way around.
Sample Input 3
8 8 .####### ######## ######## ######## ######## ######## ######## #######.
Sample Output 3
5
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
AtCoder 国には N 個の島があり、 最初、どの島にも空港・港はなく、どの島の間にも道路はありません。 王である高橋君はこれらの島の間に交通手段を用意することにしました。 具体的には、高橋君は次の操作のうち 1 つを選んで行うことを好きなだけ繰り返す事ができます。
- 1\leq i\leq N をみたす i を選び、コスト X_i を払って、島 i に空港を建設する。
- 1\leq i\leq N をみたす i を選び、コスト Y_i を払って、島 i に港を建設する。
- 1\leq i\leq M をみたす i を選び、コスト Z_i を払って、島 A_i と島 B_i の間を双方向に結ぶ道路を建設する。
高橋君の目標は、任意の相異なる 2 つの島 U, V について、 島 U からはじめて次の行動のうち 1 つを選んで行うことを好きなだけ繰り返す事で、 島 V に到達することができるようにする事です。
- 島 S,T の両方に空港がある時、島 S から島 T まで移動する。
- 島 S,T の両方に港がある時、島 S から島 T まで移動する。
- 島 S,T を結ぶ道路が存在する時、島 S から島 T まで移動する。
高橋君が目標を達成するのに必要な最小コストを求めてください。
制約
- 2 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 1\leq X_i\leq 10^9
- 1\leq Y_i\leq 10^9
- 1\leq A_i<B_i\leq N
- 1\leq Z_i\leq 10^9
- i\neq j ならば (A_i,B_i)\neq (A_j,B_j)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M X_1 X_2 \ldots X_N Y_1 Y_2 \ldots Y_N A_1 B_1 Z_1 A_2 B_2 Z_2 \vdots A_M B_M Z_M
出力
高橋君が目標を達成するのに必要な最小コストを出力せよ。
入力例 1
4 2 1 20 4 7 20 2 20 3 1 3 5 1 4 6
出力例 1
16
高橋君は次のように交通手段を建設します。
- コスト X_1=1 を払って、島 1 に空港を建設する。
- コスト X_3=4 を払って、島 3 に空港を建設する。
- コスト Y_2=2 を払って、島 2 に港を建設する。
- コスト Y_4=3 を払って、島 4 に港を建設する。
- コスト Z_2=6 を払って、島 1 と島 4 の間を結ぶ道路を建設する。
このとき、目標は達成されており、かかったコストは 16 となります。 コスト 15 以下で目標を達成する方法はないため、16 を出力します。
入力例 2
3 1 1 1 1 10 10 10 1 2 100
出力例 2
3
空港・港・道路のうち、一度も建設されないものがあっても構いません。
入力例 3
7 8 35 29 36 88 58 15 25 99 7 49 61 67 4 57 2 3 3 2 5 36 2 6 89 1 6 24 5 7 55 1 3 71 3 4 94 5 6 21
出力例 3
160
Score : 500 points
Problem Statement
The Republic of AtCoder has N islands. Initially, none of the islands has an airport or harbor, and there is no road between any two of them. Takahashi, the king, will provide some means of transportation between these islands. Specifically, he can do the following operations any number of times in any order.
- Choose an integer i such that 1\leq i\leq N and pay a cost of X_i to build an airport on island i.
- Choose an integer i such that 1\leq i\leq N and pay a cost of Y_i to build a harbor on island i.
- Choose an integer i such that 1\leq i\leq M and pay a cost of Z_i to build a road that bidirectionally connects island A_i and island B_i.
Takahashi's objective is to make it possible, for every pair of different islands U and V, to reach island V from island U when one can perform the following actions any number of times in any order.
- When islands S and T both have airports, go from island S to island T.
- When islands S and T both have harbors, go from island S to island T.
- When islands S and T are connected by a road, go from island S to island T.
Find the minimum total cost Takahashi needs to pay to achieve his objective.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 1\leq X_i\leq 10^9
- 1\leq Y_i\leq 10^9
- 1\leq A_i<B_i\leq N
- 1\leq Z_i\leq 10^9
- (A_i,B_i)\neq (A_j,B_j), if i\neq j.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M X_1 X_2 \ldots X_N Y_1 Y_2 \ldots Y_N A_1 B_1 Z_1 A_2 B_2 Z_2 \vdots A_M B_M Z_M
Output
Print the minimum total cost Takahashi needs to pay to achieve his objective.
Sample Input 1
4 2 1 20 4 7 20 2 20 3 1 3 5 1 4 6
Sample Output 1
16
Takahashi will build the following infrastructure.
- Pay a cost of X_1=1 to build an airport on island 1.
- Pay a cost of X_3=4 to build an airport on island 3.
- Pay a cost of Y_2=2 to build a harbor on island 2.
- Pay a cost of Y_4=3 to build a harbor on island 4.
- Pay a cost of Z_2=6 to build a road connecting island 1 and island 4.
Then, the objective will be achieved at a cost of 16. There is no way to achieve the objective for a cost of 15 or less, so 16 should be printed.
Sample Input 2
3 1 1 1 1 10 10 10 1 2 100
Sample Output 2
3
It is not mandatory to build all three types of facilities at least once.
Sample Input 3
7 8 35 29 36 88 58 15 25 99 7 49 61 67 4 57 2 3 3 2 5 36 2 6 89 1 6 24 5 7 55 1 3 71 3 4 94 5 6 21
Sample Output 3
160