Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
与えられる 5 つの整数 A, B, C, D, E の中に何種類の整数があるかを出力してください。
制約
- 0 \leq A, B, C, D, E \leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E
出力
答えを出力せよ。
入力例 1
31 9 24 31 24
出力例 1
3
与えられる 5 つの整数 31, 9, 24, 31, 24 の中には、9, 24, 31 という 3 種類の整数があります。 よって、3 を出力します。
入力例 2
0 0 0 0 0
出力例 2
1
Score : 100 points
Problem Statement
Print how many distinct integers there are in given five integers A, B, C, D, and E.
Constraints
- 0 \leq A, B, C, D, E \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E
Output
Print the answer.
Sample Input 1
31 9 24 31 24
Sample Output 1
3
In the given five integers 31, 9, 24, 31, and 24, there are three distinct integers 9, 24, and 31. Thus, 3 should be printed.
Sample Input 2
0 0 0 0 0
Sample Output 2
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
整数 A,B が与えられます。
以下の条件を満たす整数 x が何通りあるか求めてください。
- 条件:3 つの整数 A,B,x をうまく並べることで、等差数列を作ることができる。
なお、3 つの整数 p,q,r をこの順に並べた列が等差数列であるとは、q-p が r-q と一致することをいいます。
制約
- 1\leq A,B \leq 100
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
問題文中の条件を満たす整数 x が何通りあるかを出力せよ。 なお、答えは有限であることが証明できる。
入力例 1
5 7
出力例 1
3
以下のように、x=3,6,9 はいずれも条件を満たします。
- x=3 のとき、例えば x,A,B と並べることで等差数列 3,5,7 を作ることができます。
- x=6 のとき、例えば B,x,A と並べることで等差数列 7,6,5 を作ることができます。
- x=9 のとき、例えば A,B,x と並べることで等差数列 5,7,9 を作ることができます。
逆に、これ以外に条件を満たす x は存在しません。 よって答えは 3 です。
入力例 2
6 1
出力例 2
2
x=-4,11 のみが条件を満たします。
入力例 3
3 3
出力例 3
1
x=3 のみが条件を満たします。
Score : 100 points
Problem Statement
You are given two integers A and B.
How many integers x satisfy the following condition?
- Condition: It is possible to arrange the three integers A, B, and x in some order to form an arithmetic sequence.
A sequence of three integers p, q, and r in this order is an arithmetic sequence if and only if q-p is equal to r-q.
Constraints
- 1 \leq A,B \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the number of integers x that satisfy the condition in the problem statement. It can be proved that the answer is finite.
Sample Input 1
5 7
Sample Output 1
3
The integers x=3,6,9 all satisfy the condition as follows:
- When x=3, for example, arranging x,A,B forms the arithmetic sequence 3,5,7.
- When x=6, for example, arranging B,x,A forms the arithmetic sequence 7,6,5.
- When x=9, for example, arranging A,B,x forms the arithmetic sequence 5,7,9.
Conversely, there are no other values of x that satisfy the condition. Therefore, the answer is 3.
Sample Input 2
6 1
Sample Output 2
2
Only x=-4 and 11 satisfy the condition.
Sample Input 3
3 3
Sample Output 3
1
Only x=3 satisfies the condition.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
チェス盤のどこにコマが置かれているか答えてください。
縦 8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。
- 左から 1 列目にあるマスの名前の 1 文字目は
aである。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目はb,c,d,e,f,g,hである。 - 下から 1 行目にあるマスの名前の 2 文字目は
1である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は2,3,4,5,6,7,8である。
例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。
グリッドの状態を表す長さ 8 の 8 つの文字列 S_1,\ldots,S_8 が与えられます。
S_i の j 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。
制約
- S_i は
.および*のみからなる長さ 8 の文字列である - S_1,\ldots,S_8 の中に文字
*はちょうど 1 つ存在する。
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
出力
答えを出力せよ。
入力例 1
........ ........ ........ ........ ........ ........ ........ *.......
出力例 1
a1
問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。
入力例 2
........ ........ ........ ........ ........ .*...... ........ ........
出力例 2
b3
Score : 200 points
Problem Statement
Locate a piece on a chessboard.
We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.
- The first character of the name of a square in the 1-st column from the left is
a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left isb,c,d,e,f,g,h, respectively. - The second character of the name of a square in the 1-st row from the bottom is
1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is2,3,4,5,6,7,8, respectively.
For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.
You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise.
The character * occurs exactly once among S_1,\ldots,S_8.
Find the name of the square that has a piece on it.
Constraints
- S_i is a string of length 8 consisting of
.and*. - The character
*occurs exactly once among S_1,\ldots,S_8.
Input
The input is given from Standard Input in the following format:
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
Output
Print the answer.
Sample Input 1
........ ........ ........ ........ ........ ........ ........ *.......
Sample Output 1
a1
As explained in the problem statement, the bottom-left square is named a1.
Sample Input 2
........ ........ ........ ........ ........ .*...... ........ ........
Sample Output 2
b3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
縦 H マス、横 W マスのグリッドがあります。上から i 行目、左から j 列目のマスを (i,j) と表します。
各マスの状態は文字 C_{i,j} で表されます。C_{i,j} が . ならば (i, j) には何も置かれておらず、 # ならば箱が 1 個置かれています。
1 \leq j \leq W を満たす整数 j に対して、整数 X_j を次のように定義します。
- j 列目に置かれている箱の個数。言い換えると、C_{i,j} が
#であるような整数 i の個数。
X_1, X_2, \dots, X_W をすべて求めてください。
制約
- 1 \leq H \leq 1000
- 1 \leq W \leq 1000
- H, W は整数
- C_{i, j} は
.または#
入力
入力は以下の形式で標準入力から与えられる。
H W
C_{1,1}C_{1,2}\dots C_{1,W}
C_{2,1}C_{2,2}\dots C_{2,W}
\vdots
C_{H,1}C_{H,2}\dots C_{H,W}
出力
X_1, X_2, \dots, X_W を以下の形式に従って出力せよ。
X_1 X_2 \dots X_W
入力例 1
3 4 #..# .#.# .#.#
出力例 1
1 2 0 3
1 列目の箱が置かれているマスは (1, 1) の 1 ヵ所です。よって X_1 = 1 です。
2 列目の箱が置かれているマスは (2, 2), (3, 2) の 2 ヵ所です。よって X_2 = 2 です。
3 列目の箱が置かれているマスは存在しません。よって X_3 = 0 です。
4 列目の箱が置かれているマスは (1, 4), (2, 4), (3, 4) の 3 ヵ所です。よって X_4 = 3 です。
よって (X_1, X_2, X_3, X_4) = (1, 2, 0, 3) が答えとなります。
入力例 2
3 7 ....... ....... .......
出力例 2
0 0 0 0 0 0 0
箱が置かれているマスが存在しない場合もあります。
入力例 3
8 3 .#. ### .#. .#. .## ..# ##. .##
出力例 3
2 7 4
入力例 4
5 47 .#..#..#####..#...#..#####..#...#...###...##### .#.#...#.......#.#...#......##..#..#...#..#.... .##....#####....#....#####..#.#.#..#......##### .#.#...#........#....#......#..##..#...#..#.... .#..#..#####....#....#####..#...#...###...#####
出力例 4
0 5 1 2 2 0 0 5 3 3 3 3 0 0 1 1 3 1 1 0 0 5 3 3 3 3 0 0 5 1 1 1 5 0 0 3 2 2 2 2 0 0 5 3 3 3 3
Score : 200 points
Problem Statement
There is a grid with H rows from top to bottom and W columns from left to right. Let (i, j) denote the square at the i-th row from the top and j-th column from the left.
The squares are described by characters C_{i,j}. If C_{i,j} is ., (i, j) is empty; if it is #, (i, j) contains a box.
For integers j satisfying 1 \leq j \leq W, let the integer X_j defined as follows.
- X_j is the number of boxes in the j-th column. In other words, X_j is the number of integers i such that C_{i,j} is
#.
Find all of X_1, X_2, \dots, X_W.
Constraints
- 1 \leq H \leq 1000
- 1 \leq W \leq 1000
- H and W are integers.
- C_{i, j} is
.or#.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}C_{1,2}\dots C_{1,W}
C_{2,1}C_{2,2}\dots C_{2,W}
\vdots
C_{H,1}C_{H,2}\dots C_{H,W}
Output
Print X_1, X_2, \dots, X_W in the following format:
X_1 X_2 \dots X_W
Sample Input 1
3 4 #..# .#.# .#.#
Sample Output 1
1 2 0 3
In the 1-st column, one square, (1, 1), contains a box. Thus, X_1 = 1.
In the 2-nd column, two squares, (2, 2) and (3, 2), contain a box. Thus, X_2 = 2.
In the 3-rd column, no squares contain a box. Thus, X_3 = 0.
In the 4-th column, three squares, (1, 4), (2, 4), and (3, 4), contain a box. Thus, X_4 = 3.
Therefore, the answer is (X_1, X_2, X_3, X_4) = (1, 2, 0, 3).
Sample Input 2
3 7 ....... ....... .......
Sample Output 2
0 0 0 0 0 0 0
There may be no square that contains a box.
Sample Input 3
8 3 .#. ### .#. .#. .## ..# ##. .##
Sample Output 3
2 7 4
Sample Input 4
5 47 .#..#..#####..#...#..#####..#...#...###...##### .#.#...#.......#.#...#......##..#..#...#..#.... .##....#####....#....#####..#.#.#..#......##### .#.#...#........#....#......#..##..#...#..#.... .#..#..#####....#....#####..#...#...###...#####
Sample Output 4
0 5 1 2 2 0 0 5 3 3 3 3 0 0 1 1 3 1 1 0 0 5 3 3 3 3 0 0 5 1 1 1 5 0 0 3 2 2 2 2 0 0 5 3 3 3 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
英大文字からなる長さ 3 の文字列 T が、英小文字からなる文字列 S の 空港コード であるとは、 T が S から次のいずれかの方法により得られることとします。
- S の長さ 3 の(連続とは限らない)部分列をとり、それを英大文字に変換したものを T とする
- S の長さ 2 の(連続とは限らない)部分列をとり、それを英大文字に変換したものの末尾に
Xを追加したものを T とする
文字列 S, T が与えられるので、 T が S の空港コードであるか判定してください。
制約
- S は英小文字からなる長さ 3 以上 10^5 以下の文字列
- T は英大文字からなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
T が S の空港コードであるならば Yes を、そうでないならば No を出力せよ。
入力例 1
narita NRT
出力例 1
Yes
narita の部分列 nrt を英大文字に変換した文字列 NRT は、 narita の空港コードです。
入力例 2
losangeles LAX
出力例 2
Yes
losangeles の部分列 la を英大文字に変換した文字列 LA の末尾に X を追加したもの LAX は、 losangeles の空港コードです。
入力例 3
snuke RNG
出力例 3
No
Score: 300 points
Problem Statement
A string T of length 3 consisting of uppercase English letters is an airport code for a string S of lowercase English letters if and only if T can be derived from S by one of the following methods:
- Take a subsequence of length 3 from S (not necessarily contiguous) and convert it to uppercase letters to form T.
- Take a subsequence of length 2 from S (not necessarily contiguous), convert it to uppercase letters, and append
Xto the end to form T.
Given strings S and T, determine if T is an airport code for S.
Constraints
- S is a string of lowercase English letters with a length between 3 and 10^5, inclusive.
- T is a string of uppercase English letters with a length of 3.
Input
The input is given from Standard Input in the following format:
S T
Output
Print Yes if T is an airport code for S, and No otherwise.
Sample Input 1
narita NRT
Sample Output 1
Yes
The subsequence nrt of narita, when converted to uppercase, forms the string NRT, which is an airport code for narita.
Sample Input 2
losangeles LAX
Sample Output 2
Yes
The subsequence la of losangeles, when converted to uppercase and appended with X, forms the string LAX, which is an airport code for losangeles.
Sample Input 3
snuke RNG
Sample Output 3
No
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A = (a_1, a_2, \dots, a_N) があります。
以下で説明される Q 個のクエリに答えてください。
- クエリ i : 整数の組 (x_i, k_i) が与えられます。A の要素を a_1, a_2, \dots と前から順に見ていったときに、数 x_i が k_i 回目に登場するのは A の前から何番目の要素を見たときかを出力してください。
ただし条件を満たす要素が存在しない場合は -1 を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq a_i \leq 10^9 (1 \leq i \leq N)
- 0 \leq x_i \leq 10^9 (1 \leq i \leq Q)
- 1 \leq k_i \leq N (1 \leq i \leq Q)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N Q a_1 a_2 \dots a_N x_1 k_1 x_2 k_2 \vdots x_Q k_Q
出力
Q 行出力せよ。i 行目ではクエリ i に対する答えを出力せよ。
入力例 1
6 8 1 1 2 3 1 2 1 1 1 2 1 3 1 4 2 1 2 2 2 3 4 1
出力例 1
1 2 5 -1 3 6 -1 -1
A の中で 1 は a_1, a_2, a_5 に登場します。よって、クエリ 1 からクエリ 4 の答えは順に 1, 2, 5, -1 となります。
入力例 2
3 2 0 1000000000 999999999 1000000000 1 123456789 1
出力例 2
2 -1
Score : 300 points
Problem Statement
We have a sequence of N numbers: A = (a_1, a_2, \dots, a_N).
Process the Q queries explained below.
- Query i: You are given a pair of integers (x_i, k_i). Let us look at the elements of A one by one from the beginning: a_1, a_2, \dots Which element will be the k_i-th occurrence of the number x_i?
Print the index of that element, or -1 if there is no such element.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq a_i \leq 10^9 (1 \leq i \leq N)
- 0 \leq x_i \leq 10^9 (1 \leq i \leq Q)
- 1 \leq k_i \leq N (1 \leq i \leq Q)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q a_1 a_2 \dots a_N x_1 k_1 x_2 k_2 \vdots x_Q k_Q
Output
Print Q lines. The i-th line should contain the answer to Query i.
Sample Input 1
6 8 1 1 2 3 1 2 1 1 1 2 1 3 1 4 2 1 2 2 2 3 4 1
Sample Output 1
1 2 5 -1 3 6 -1 -1
1 occurs in A at a_1, a_2, a_5. Thus, the answers to Query 1 through 4 are 1, 2, 5, -1 in this order.
Sample Input 2
3 2 0 1000000000 999999999 1000000000 1 123456789 1
Sample Output 2
2 -1
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
配点 : 425 点
問題文
この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
1 から N の番号がついた N 本のジュースがあります。 このうちちょうど 1 本が腐っていることが判明しました。 そのジュースを微量でも飲むと、翌日お腹を壊してしまいます。
高橋君は翌日までに腐ったジュースを特定しなければなりません。 高橋君はそのために必要な最小の数の友人を呼び、それぞれに N 本のジュースのうちの一部を振る舞うことにしました。 各友人には何本でもジュースを与えることができ、各ジュースは何人の友人にでも与えることができます。
呼ぶ友人の数とジュースの与え方を出力して、翌日に各友人がお腹を壊したかどうかの情報を受け取り、腐ったジュースの番号を出力してください。
制約
- N は整数
- 2 \leq N \leq 100
入出力
この問題はインタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
対話を行う前にジャッジは、腐ったジュースの番号 X として 1 以上 N 以下の整数を秘密裏に選択します。 X の値はあなたには与えられません。また、対話の途中で X の値が制約および以前の出力に矛盾しない範囲で変わる場合があります。
まず、ジャッジから N が入力から与えられます。
N
あなたは呼ぶ友人の数 M を出力し改行してください。
M
さらに、あなたは次に述べる M 回の出力からなる手続きを行ってください。 i = 1, 2, \ldots, M について i 回目の出力では、 i 番目の友人に飲ませるジュースの本数 K_i および、それら K_i 本のジュースの番号を昇順に並べた列 A_{i, 1}, A_{i, 2}, \ldots, A_{i, K_i} を下記の形式で空白区切りで出力し、改行してください。
K_i A_{i, 1} A_{i, 2} \ldots A_{i, K_i}
その後ジャッジから、各友人が翌日にお腹を壊したかどうかの情報が、0 と 1 のみからなる長さ M の文字列 S として与えられます。
S
i = 1, 2, \ldots, M について、S の i 文字目が 1 のとき、かつそのときに限り、i 番目の友人がお腹を壊したことを表します。
それに対し、あなたは腐ったジュースの番号 X' を出力し、改行してください。
X'
その後、直ちにプログラムを終了してください。
あなたが出力した M が N 本のジュースから腐ったジュースを特定するために必要な最小の友人の数であり、かつ、あなたが出力した X' が腐ったジュースの番号 X と一致していれば、正解となります。
注意点
- 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。 特に、プログラムの実行中に実行時エラーが起こった場合に、ジャッジ結果が ではなく や TLE になる可能性があることに注意してください。
- X' を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
- この問題のジャッジはアダプティブです。つまり、制約および以前の出力に矛盾しない範囲で X の値が変わる場合があります。
入出力例
以下は、N = 3 の場合の入出力例です。
| 入力 | 出力 | 説明 |
|---|---|---|
3 |
ジュースの本数 N が与えられます。 | |
2 |
呼ぶ友人の数 M を出力します。 | |
2 1 2 |
1 人目の友人にジュース 1 とジュース 2 を与えます。 | |
1 2 |
2 人目の友人に、ジュース 2 を与えます。 | |
10 |
翌日に各友人がお腹を壊したかどうかを表す文字列 S が与えられます。 | |
1 |
腐ったジュースの番号を出力します。 | |
Score: 425 points
Problem Statement
This is an interactive problem (a type of problem where your program interacts with the judge program through Standard Input and Output).
There are N bottles of juice, numbered 1 to N. It has been discovered that exactly one of these bottles has gone bad. Even a small sip of the spoiled juice will cause stomach upset the next day.
Takahashi must identify the spoiled juice by the next day. To do this, he decides to call the minimum necessary number of friends and serve them some of the N bottles of juice. He can give any number of bottles to each friend, and each bottle of juice can be given to any number of friends.
Print the number of friends to call and how to distribute the juice, then receive information on whether each friend has an upset stomach the next day, and print the spoiled bottle's number.
Constraints
- N is an integer.
- 2 \leq N \leq 100
Input/Output
This is an interactive problem (a type of problem where your program interacts with the judge program through Standard Input and Output).
Before the interaction, the judge secretly selects an integer X between 1 and N as the spoiled bottle's number. The value of X is not given to you. Also, the value of X may change during the interaction as long as it is consistent with the constraints and previous outputs.
First, the judge will give you N as input.
N
You should print the number of friends to call, M, followed by a newline.
M
Next, you should perform the following procedure to print M outputs. For i = 1, 2, \ldots, M, the i-th output should contain the number K_i of bottles of juice you will serve to the i-th friend, and the K_i bottles' numbers in ascending order, A_{i, 1}, A_{i, 2}, \ldots, A_{i, K_i}, separated by spaces, followed by a newline.
K_i A_{i, 1} A_{i, 2} \ldots A_{i, K_i}
Then, the judge will inform you whether each friend has a stomach upset the next day by giving you a string S of length M consisting of 0 and 1.
S
For i = 1, 2, \ldots, M, the i-th friend has a stomach upset if and only if the i-th character of S is 1.
You should respond by printing the number of the spoiled juice bottle X', followed by a newline.
X'
Then, terminate the program immediately.
If the M you printed is the minimum necessary number of friends to identify the spoiled juice out of the N bottles, and the X' you printed matches the spoiled bottle's number X, then your program is considered correct.
Notes
- Each output should end with a newline and flushing Standard Output. Otherwise, you may receive a TLE verdict.
- The verdict is indeterminate if your program prints an invalid output during the interaction or terminates prematurely. In particular, note that if a runtime error occurs during the execution of the program, the verdict may be or TLE instead of .
- Terminate the program immediately after printing X'. Otherwise, the verdict is indeterminate.
- The judge for this problem is adaptive, meaning that the value of X may change as long as it is consistent with the constraints and previous outputs.
Sample Input/Output
Below is an interaction with N = 3.
| Input | Output | Description |
|---|---|---|
3 |
The number of bottles, N, is given. | |
2 |
Print the number of friends to call, M. | |
2 1 2 |
Serve juice 1 and juice 2 to the first friend. | |
1 2 |
Serve juice 2 to the second friend. | |
10 |
The string S is given, indicating whether each friend has a stomach upset the next day. | |
1 |
Print the spoiled bottle's number. | |
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
文字列 S が与えられます。高橋君はこの文字列から以下の手順にしたがって新しい文字列 T を作ります。
- まず、S の文字のうちの一つ以上に印をつける。ただし、印をつけた文字どうしが隣り合ってはならない。
- 次に、印がついていない文字を全て削除する。
- 最後に、残った文字列を T とする。ただし、この時に文字を並び替えてはならない。
T としてありうる文字列は何種類ありますか? (10^9 + 7) で割ったあまりを求めてください。
制約
- S は英小文字のみからなる長さ 1 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
T としてありうる文字列の種類数を (10^9 + 7) で割ったあまりを出力せよ。
入力例 1
abc
出力例 1
4
T としてありうるものは a、 b、 c、 ac の 4 つです。
S の 1 文字目のみに印をつけたとき T は a、
S の 2 文字目のみに印をつけたとき T は b、
S の 3 文字目のみに印をつけたとき T は c、
S の 1 文字目と 3 文字目のみに印をつけたとき T は ac、
となります。例えば 1 文字目と 2 文字目の両方に印をつけることはできないことに注意してください。
入力例 2
aa
出力例 2
1
T としてありうるものは a のみです。
印をつけた位置が異なっていても T が同じ文字列となる可能性があることに注意してください。
入力例 3
acba
出力例 3
6
T としてありうるものは a、 b、 c、 aa、 ab、 ca の 6 つです。
入力例 4
chokudai
出力例 4
54
Score : 500 points
Problem Statement
Given is a string S. From this string, Takahashi will make a new string T as follows.
- First, mark one or more characters in S. Here, no two marked characters should be adjacent.
- Next, delete all unmarked characters.
- Finally, let T be the remaining string. Here, it is forbidden to change the order of the characters.
How many strings are there that can be obtained as T? Find the count modulo (10^9 + 7).
Constraints
- S is a string of length between 1 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of different strings that can be obtained as T, modulo (10^9 + 7).
Sample Input 1
abc
Sample Output 1
4
There are four strings that can be obtained as T: a, b, c, and ac.
Marking the first character of S yields a;
marking the second character of S yields b;
marking the third character of S yields c;
marking the first and third characters of S yields ac.
Note that it is forbidden to, for example, mark both the first and second characters.
Sample Input 2
aa
Sample Output 2
1
There is just one string that can be obtained as T, which is a.
Note that marking different positions may result in the same string.
Sample Input 3
acba
Sample Output 3
6
There are six strings that can be obtained as T: a, b, c, aa, ab, and ca.
Sample Input 4
chokudai
Sample Output 4
54