実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
N 問の問題からなるコンテストが開催され、i\ (1\leq i\leq N) 問目の配点は A_i 点でした。
すぬけくんはこのコンテストに参加し、B_1,B_2,\ldots,B_M 問目の M 問を解きました。 すぬけくんの総得点を求めてください。
ただし、総得点とは解いた問題の配点の総和を意味するものとします。
制約
- 1\leq M \leq N \leq 100
- 1\leq A_i \leq 100
- 1\leq B_1 < B_2 < \ldots < B_M \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
出力
答えを整数として出力せよ。
入力例 1
3 2 10 20 30 1 3
出力例 1
40
すぬけくんは 1 問目と 3 問目を解きました。 配点はそれぞれ 10 点と 30 点なので、総得点は 10+30=40 点です。
入力例 2
4 1 1 1 1 100 4
出力例 2
100
入力例 3
8 4 22 75 26 45 72 81 47 29 4 6 7 8
出力例 3
202
Score : 100 points
Problem Statement
There was a contest with N problems. The i-th (1\leq i\leq N) problem was worth A_i points.
Snuke took part in this contest and solved M problems: the B_1-th, B_2-th, \ldots, and B_M-th ones. Find his total score.
Here, the total score is defined as the sum of the points for the problems he solved.
Constraints
- 1\leq M \leq N \leq 100
- 1\leq A_i \leq 100
- 1\leq B_1 < B_2 < \ldots < B_M \leq N
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
Output
Print the answer as an integer.
Sample Input 1
3 2 10 20 30 1 3
Sample Output 1
40
Snuke solved the 1-st and 3-rd problems, which are worth 10 and 30 points, respectively. Thus, the total score is 10+30=40 points.
Sample Input 2
4 1 1 1 1 100 4
Sample Output 2
100
Sample Input 3
8 4 22 75 26 45 72 81 47 29 4 6 7 8
Sample Output 3
202
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
N 個の文字列 S_1,S_2,\ldots,S_N がこの順番で与えられます。
S_N,S_{N-1},\ldots,S_1 の順番で出力してください。
制約
- 1\leq N \leq 10
- N は整数
- S_i は英小文字、英大文字、数字からなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
N 行出力せよ。 i\ (1\leq i \leq N) 行目には、S_{N+1-i} を出力せよ。
入力例 1
3 Takahashi Aoki Snuke
出力例 1
Snuke Aoki Takahashi
N=3、S_1= Takahashi
、S_2= Aoki
、S_3= Snuke
です。
よって、Snuke
、Aoki
、Takahashi
の順で出力します。
入力例 2
4 2023 Year New Happy
出力例 2
Happy New Year 2023
与えられる文字列が数字を含むこともあります。
Score : 100 points
Problem Statement
You are given N strings S_1,S_2,\ldots,S_N in this order.
Print S_N,S_{N-1},\ldots,S_1 in this order.
Constraints
- 1\leq N \leq 10
- N is an integer.
- S_i is a string of length between 1 and 10, inclusive, consisting of lowercase English letters, uppercase English letters, and digits.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print N lines. The i-th (1\leq i \leq N) line should contain S_{N+1-i}.
Sample Input 1
3 Takahashi Aoki Snuke
Sample Output 1
Snuke Aoki Takahashi
We have N=3, S_1= Takahashi
, S_2= Aoki
, and S_3= Snuke
.
Thus, you should print Snuke
, Aoki
, and Takahashi
in this order.
Sample Input 2
4 2023 Year New Happy
Sample Output 2
Happy New Year 2023
The given strings may contain digits.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
英小文字と ?
からなる文字列 T と、英小文字のみからなる文字列 U が与えられます。
T は、英小文字のみからなる文字列 S のちょうど 4 文字を ?
で置き換えることで得られた文字列です。
S が U を連続部分文字列として含んでいた可能性があるかどうか判定してください。
制約
- T は長さ 4 以上 10 以下の英小文字と
?
からなる文字列 - T にはちょうど 4 つの
?
が含まれる - U は長さ 1 以上 |T| 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
T U
出力
S が U を部分文字列として含んでいた可能性があるならば Yes
を、そうでないならば No
を出力せよ。
入力例 1
tak??a?h? nashi
出力例 1
Yes
例えば、S が takanashi
である場合、これは nashi
を連続部分文字列として含みます。
入力例 2
??e??e snuke
出力例 2
No
?
がどのような文字であっても、S は snuke
を連続部分文字列として含むことがありません。
入力例 3
???? aoki
出力例 3
Yes
Score : 250 points
Problem Statement
You are given a string T consisting of lowercase English letters and ?
, and a string U consisting of lowercase English letters.
The string T is obtained by taking some lowercase-only string S and replacing exactly four of its characters with ?
.
Determine whether it is possible that the original string S contained U as a contiguous substring.
Constraints
- T is a string of length between 4 and 10, inclusive, consisting of lowercase letters and
?
. - T contains exactly four occurrences of
?
. - U is a string of length between 1 and |T|, inclusive, consisting of lowercase letters.
Input
The input is given from Standard Input in the following format:
T U
Output
Print Yes
if it is possible that the original string S contained U as a contiguous substring; otherwise, print No
.
Sample Input 1
tak??a?h? nashi
Sample Output 1
Yes
For example, if S is takanashi
, it contains nashi
as a contiguous substring.
Sample Input 2
??e??e snuke
Sample Output 2
No
No matter what characters replace the ?
s in T, S cannot contain snuke
as a contiguous substring.
Sample Input 3
???? aoki
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
1 から N の番号がついた N 人の人がいます。
人 i はキーエンス本社ビルの建築面積を S_i 平方メートルであると予想しました。
キーエンス本社ビルは下図のような形をしています。ただし、a,b はある 正の整数 です。
つまり、キーエンス本社ビルの建築面積は 4ab+3a+3b 平方メートルと表されます。
N 人のうち、この情報のみによって、予想した面積が確実に誤りであるとわかる人数を求めてください。
制約
- 1 \leq N \leq 20
- 1 \leq S_i \leq 1000
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N S_1 \ldots S_N
出力
答えを出力せよ。
入力例 1
3 10 20 39
出力例 1
1
a=1,b=1 のとき面積は 10 平方メートル、a=2,b=3 のとき面積は 39 平方メートルとなります。
しかし a,b がどのような正の整数であったとしても面積が 20 平方メートルになることはありません。
よって、人 2 の予想だけは確実に誤りであることがわかります。
入力例 2
5 666 777 888 777 666
出力例 2
3
Score : 200 points
Problem Statement
There are N people numbered 1 to N.
Person i guessed the building area of KEYENCE headquarters building to be S_i square meters.
The shape of KEYENCE headquarters building is shown below, where a and b are some positive integers.
That is, the building area of the building can be represented as 4ab+3a+3b.
Based on just this information, how many of the N people are guaranteed to be wrong in their guesses?
Constraints
- 1 \leq N \leq 20
- 1 \leq S_i \leq 1000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N S_1 \ldots S_N
Output
Print the answer.
Sample Input 1
3 10 20 39
Sample Output 1
1
The area would be 10 square meters if a=1,b=1, and 39 square meters if a=2,b=3.
However, no pair of positive integers a and b would make the area 20 square meters.
Thus, we can only be sure that Person 2 guessed wrong.
Sample Input 2
5 666 777 888 777 666
Sample Output 2
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英小文字からなる 2 つの文字列 S, T が与えられます。 次の操作を好きな回数( 0 回でも良い)行うことで、S を T と一致させることができるかを判定してください。
S において同じ文字が 2 文字連続しているところの間に、その文字と同じ文字を 1 つ挿入する。 すなわち、下記の 3 つの手順からなる操作を行う。
- 現在の S の長さを N とし、S = S_1S_2\ldots S_N とする。
- 1 以上 N-1 以下の整数 i であって、S_i = S_{i+1} を満たすものを 1 つ選択する。(ただし、そのような i が存在しない場合は、何もせずに手順 3.をスキップして操作を終了する。)
- S の i 文字目と i+1 文字目の間に文字 S_i(= S_{i+1}) を 1 つ挿入する。その結果、S は長さ N+1 の文字列 S_1S_2\ldots S_i S_i S_{i+1} \ldots S_N となる。
制約
- S と T はそれぞれ英小文字からなる長さ 2 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
S を T と一致させることができる場合は Yes
を、そうでない場合は No
を出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
abbaac abbbbaaac
出力例 1
Yes
下記の 3 回の操作によって、S = abbaac
を T = abbbbaaac
に一致させることができます。
- まず、S の 2 文字目と 3 文字目の間に
b
を挿入する。その結果、S =abbbaac
となる。 - 次に、再び S の 2 文字目と 3 文字目の間に
b
を挿入する。その結果、S =abbbbaac
となる。 - 最後に、S の 6 文字目と 7 文字目の間に
a
を挿入する。その結果、S =abbbbaaac
となる。
よって、Yes
を出力します。
入力例 2
xyzz xyyzz
出力例 2
No
どのように操作を行っても、 S = xyzz
を T = xyyzz
に一致させることはできません。
よって、No
を出力します。
Score : 300 points
Problem Statement
You are given two strings S and T. Determine whether it is possible to make S equal T by performing the following operation some number of times (possibly zero).
Between two consecutive equal characters in S, insert a character equal to these characters. That is, take the following three steps.
- Let N be the current length of S, and S = S_1S_2\ldots S_N.
- Choose an integer i between 1 and N-1 (inclusive) such that S_i = S_{i+1}. (If there is no such i, do nothing and terminate the operation now, skipping step 3.)
- Insert a single copy of the character S_i(= S_{i+1}) between the i-th and (i+1)-th characters of S. Now, S is a string of length N+1: S_1S_2\ldots S_i S_i S_{i+1} \ldots S_N.
Constraints
- Each of S and T is a string of length between 2 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S T
Output
If it is possible to make S equal T, print Yes
; otherwise, print No
.
Note that the judge is case-sensitive.
Sample Input 1
abbaac abbbbaaac
Sample Output 1
Yes
You can make S = abbaac
equal T = abbbbaaac
by the following three operations.
- First, insert
b
between the 2-nd and 3-rd characters of S. Now, S =abbbaac
. - Next, insert
b
again between the 2-nd and 3-rd characters of S. Now, S =abbbbaac
. - Lastly, insert
a
between the 6-th and 7-th characters of S. Now, S =abbbbaaac
.
Thus, Yes
should be printed.
Sample Input 2
xyzz xyyzz
Sample Output 2
No
No sequence of operations makes S = xyzz
equal T = xyyzz
.
Thus, No
should be printed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。
S の空でない部分文字列であって、1 種類の文字のみからなるものの数を求めてください。 ただし、文字列として等しい部分文字列同士は、取り出し方が異なっても区別しません。
なお、S の空でない部分文字列とは、S の先頭から 0 文字以上、末尾から 0 文字以上削除して得られる文字列のうち、長さが 1 以上であるもののことをいいます。
例えば、ab
や abc
は abc
の空でない部分文字列ですが、ac
や空文字列は abc
の空でない部分文字列ではありません。
制約
- 1 \leq N \leq 2\times 10^5
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の空でない部分文字列であって、1 種類の文字のみからなるものの数を出力せよ。
入力例 1
6 aaabaa
出力例 1
4
S の空でない部分文字列であって、1 種類の文字のみからなるものは a
, aa
, aaa
, b
の 4 つです。
S から a
や aa
を取り出す方法は 1 通りではありませんが、それぞれ 1 回ずつしか数えないことに注意してください。
入力例 2
1 x
出力例 2
1
入力例 3
12 ssskkyskkkky
出力例 3
8
Score : 300 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters.
Find the number of non-empty substrings of S that are repetitions of one character. Here, two substrings that are equal as strings are not distinguished even if they are obtained differently.
A non-empty substring of S is a string of length at least one obtained by deleting zero or more characters from the beginning and zero or more characters from the end of S. For example, ab
and abc
are non-empty substrings of abc
, while ac
and the empty string are not.
Constraints
- 1 \leq N \leq 2\times 10^5
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the number of non-empty substrings of S that are repetitions of one character.
Sample Input 1
6 aaabaa
Sample Output 1
4
The non-empty substrings of S that are repetitions of one character are a
, aa
, aaa
, and b
; there are four of them. Note that there are multiple ways to obtain a
or aa
from S, but each should only be counted once.
Sample Input 2
1 x
Sample Output 2
1
Sample Input 3
12 ssskkyskkkky
Sample Output 3
8
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
H 行 W 列のグリッドがあります。上から i 行目、左から j 列目のマスをマス (i, j) と呼びます。
各マスには o
、x
、.
のうちいずれかの文字が書かれています。
各マスに書かれた文字は H 個の長さ W の文字列 S_1, S_2, \ldots, S_H で表され、
マス (i, j) に書かれた文字は、文字列 S_i の j 文字目と一致します。
このグリッドに対して、下記の操作を 0 回以上好きな回数だけ繰り返します。
.
が書かれているマスを 1 個選び、そのマスに書かれた文字をo
に変更する。
その結果、縦方向または横方向に連続した K 個のマスであってそれらに書かれた文字がすべて o
であるようなものが存在する(
すなわち、下記の 2 つの条件のうち少なくとも一方を満たす)ようにすることが可能かを判定し、可能な場合はそのために行う操作回数の最小値を出力してください。
- 1 \leq i \leq H かつ 1 \leq j \leq W-K+1 を満たす整数の組 (i, j) であって、マス (i, j), (i, j+1), \ldots, (i, j+K-1) に書かれた文字が
o
であるものが存在する。 - 1 \leq i \leq H-K+1 かつ 1 \leq j \leq W を満たす整数の組 (i, j) であって、マス (i, j), (i+1, j), \ldots, (i+K-1, j) に書かれた文字が
o
であるものが存在する。
制約
- H, W, K は整数
- 1 \leq H
- 1 \leq W
- H \times W \leq 2 \times 10^5
- 1 \leq K \leq \max\lbrace H, W \rbrace
- S_i は
o
、x
、.
のみからなる長さ W の文字列
入力
入力は以下の形式で標準入力から与えられる。
H W K S_1 S_2 \vdots S_H
出力
問題文中の条件を満たすことが不可能な場合は -1
を、可能な場合はそのために行う操作回数の最小値を出力せよ。
入力例 1
3 4 3 xo.x ..o. xx.o
出力例 1
2
操作を 2 回行って、例えばマス (2, 1) とマス (2, 2) に書かれた文字をそれぞれ o
に変更することで問題文中の条件を満たすことができ、これが最小の操作回数です。
入力例 2
4 2 3 .o .o .o .o
出力例 2
0
操作を一度も行わなくても問題文中の条件を満たします。
入力例 3
3 3 3 x.. ..x .x.
出力例 3
-1
問題文中の条件を満たすことは不可能なので、-1
を出力します。
入力例 4
10 12 6 ......xo.o.. x...x.....o. x........... ..o...x..... .....oo..... o.........x. ox.oox.xx..x ....o...oox. ..o.....x.x. ...o........
出力例 4
3
Score: 400 points
Problem Statement
There is a grid with H rows and W columns. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left.
Each cell contains one of the characters o
, x
, and .
. The characters written in each cell are represented by H strings S_1, S_2, \ldots, S_H of length W; the character written in cell (i, j) is the j-th character of the string S_i.
For this grid, you may repeat the following operation any number of times, possibly zero:
- Choose one cell with the character
.
and change the character in that cell too
.
Determine if it is possible to have a sequence of K horizontally or vertically consecutive cells with o
written in all cells (in other words, satisfy at least one of the following two conditions). If it is possible, print the minimum number of operations required to achieve this.
- There is an integer pair (i, j) satisfying 1 \leq i \leq H and 1 \leq j \leq W-K+1 such that the characters in cells (i, j), (i, j+1), \ldots, (i, j+K-1) are all
o
. - There is an integer pair (i, j) satisfying 1 \leq i \leq H-K+1 and 1 \leq j \leq W such that the characters in cells (i, j), (i+1, j), \ldots, (i+K-1, j) are all
o
.
Constraints
- H, W, and K are integers.
- 1 \leq H
- 1 \leq W
- H \times W \leq 2 \times 10^5
- 1 \leq K \leq \max\lbrace H, W \rbrace
- S_i is a string of length W consisting of the characters
o
,x
, and.
.
Input
The input is given from Standard Input in the following format:
H W K S_1 S_2 \vdots S_H
Output
If it is impossible to satisfy the condition in the problem statement, print -1
. Otherwise, print the minimum number of operations required to do so.
Sample Input 1
3 4 3 xo.x ..o. xx.o
Sample Output 1
2
By operating twice, for example, changing the characters in cells (2, 1) and (2, 2) to o
, you can satisfy the condition in the problem statement, and this is the minimum number of operations required.
Sample Input 2
4 2 3 .o .o .o .o
Sample Output 2
0
The condition is satisfied without performing any operations.
Sample Input 3
3 3 3 x.. ..x .x.
Sample Output 3
-1
It is impossible to satisfy the condition, so print -1
.
Sample Input 4
10 12 6 ......xo.o.. x...x.....o. x........... ..o...x..... .....oo..... o.........x. ox.oox.xx..x ....o...oox. ..o.....x.x. ...o........
Sample Output 4
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
頂点に 1 から N の番号が、辺に 1 から M の番号がついた N 頂点 M 辺の単純有向グラフが与えられます。辺 i は頂点 u_i から頂点 v_i への有向辺です。
また、あなたは次の操作を 0 回以上何度でも行えます。
- 相異なる頂点 x,y であって頂点 x から頂点 y への有向辺が存在しないようなものを選ぶ。そして、頂点 x から頂点 y への有向辺を追加する。
このグラフが次の条件を満たす状態にするために最小で何回操作を行う必要があるかを求めてください。
- 相異なる頂点 a,b,c すべてについて、頂点 a から頂点 b への有向辺と頂点 b から頂点 c への有向辺がともに存在するならば頂点 a から頂点 c への有向辺も存在する。
制約
- 3 \leq N \leq 2000
- 0 \leq M \leq 2000
- 1 \leq u_i ,v_i \leq N
- u_i \neq v_i
- i \neq j ならば (u_i,v_i) \neq (u_j,v_j)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 \vdots u_M v_M
出力
答えを出力せよ。
入力例 1
4 3 2 4 3 1 4 3
出力例 1
3
初め、一例として頂点 2,4,3 について、頂点 2 から頂点 4 への有向辺と頂点 4 から頂点 3 への有向辺がともに存在するにもかかわらず、頂点 2 から頂点 3 への有向辺は存在せず、条件を満たさない状態です。
そこで、以下の 3 本の有向辺を追加すると条件を満たす状態になります。
- 頂点 2 から頂点 3 への有向辺
- 頂点 2 から頂点 1 への有向辺
- 頂点 4 から頂点 1 への有向辺
一方、3 本未満の追加で条件を満たす状態には出来ないため、答えは 3 です。
入力例 2
292 0
出力例 2
0
入力例 3
5 8 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1
出力例 3
12
Score : 500 points
Problem Statement
You are given a simple directed graph with N vertices numbered 1 to N and M edges numbered 1 to M. Edge i is a directed edge from vertex u_i to vertex v_i.
You may perform the following operation zero or more times.
- Choose distinct vertices x and y such that there is no directed edge from vertex x to vertex y, and add a directed edge from vertex x to vertex y.
Find the minimum number of times you need to perform the operation to make the graph satisfy the following condition.
- For every triple of distinct vertices a, b, and c, if there are directed edges from vertex a to vertex b and from vertex b to vertex c, there is also a directed edge from vertex a to vertex c.
Constraints
- 3 \leq N \leq 2000
- 0 \leq M \leq 2000
- 1 \leq u_i ,v_i \leq N
- u_i \neq v_i
- (u_i,v_i) \neq (u_j,v_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 u_1 v_1 \vdots u_M v_M
Output
Print the answer.
Sample Input 1
4 3 2 4 3 1 4 3
Sample Output 1
3
Initially, the condition is not satisfied because, for instance, for vertices 2, 4, and 3, there are directed edges from vertex 2 to vertex 4 and from vertex 4 to vertex 3, but not from vertex 2 to vertex 3.
You can make the graph satisfy the condition by adding the following three directed edges:
- one from vertex 2 to vertex 3,
- one from vertex 2 to vertex 1, and
- one from vertex 4 to vertex 1.
On the other hand, the condition cannot be satisfied by adding two or fewer edges, so the answer is 3.
Sample Input 2
292 0
Sample Output 2
0
Sample Input 3
5 8 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1
Sample Output 3
12
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
あなたとジャッジは下記の手順を行います。 手順はフェイズ 1 とフェイズ 2 からなり、まずフェイズ 1 を行った直後、続けてフェイズ 2 を行います。
(フェイズ 1 )
- ジャッジが 1 以上 10^9 以下の整数 N を決める。この整数は隠されている。
- あなたは 1 以上 110 以下の整数 M を出力する。
- さらにあなたは、すべての i = 1, 2, \ldots, M について 1 \leq A_i \leq M を満たす、長さ M の整数列 A=(A_1,A_2,\ldots,A_M) を出力する。
(フェイズ 2 )
- ジャッジから、長さ M の整数列 B=(B_1,B_2,\ldots,B_M) が与えられる。ここで、 B_i = f^N(i) である。 f(i) は 1 以上 M 以下の整数 i に対し f(i)=A_i で定められ、 f^N(i) は i を f(i) で置き換える操作を N 回行った際に得られる整数である。
- あなたは、B の情報から、ジャッジが決めた整数 N を特定し、N を出力する。
上記の手順を行った後、直ちにプログラムを終了することで正解となります。
制約
- N は 1 以上 10^9 以下の整数
入出力
この問題はインタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
(フェイズ 1 )
- まず、1 以上 110 以下の整数 M を出力してください。出力後、必ず改行してください。
M
- その後、空白区切りで 1 以上 M 以下の整数からなる長さ M の整数列 A=(A_1,A_2,\ldots,A_M) を出力してください。出力後、必ず改行してください。
A_1 A_2 \ldots A_M
(フェイズ 2 )
- まず、長さ M の整数列 B=(B_1,B_2,\ldots,B_M) が入力から与えられます。
B_1 B_2 \ldots B_M
- 整数 N を求め、出力してください。出力後、必ず改行してください。
N
不正な出力がなされた場合、ジャッジは -1
を出力します。この時、提出はすでに不正解と判定されています。ジャッジプログラムはこの時点で終了するため、あなたのプログラムも終了するのが望ましいです。
注意点
- 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
- 答えを出力したら(または
-1
を受け取ったら)直ちにプログラムを正常終了してください。そうしなかった場合、ジャッジ結果は不定です。 - 特に、余計な改行も不正なフォーマットの出力とみなされるので注意してください。
入出力例
以下は、N = 2 の場合の入出力例です。
入力 | 出力 | 説明 |
---|---|---|
ジャッジは N=2 と決めました。N は入力としては与えられず、隠されています。 | ||
4 |
M を出力します。 | |
2 3 4 4 |
A=(2,3,4,4) を出力します。 | |
3 4 4 4 |
f^2(1)=3,f^2(2)=4,f^2(3)=4,f^2(4)=4 なので、ジャッジは B=(3,4,4,4) をあなたのプログラムに与えます。 | |
2 |
B から N=2 であると特定しました。 N を出力し、プログラムを正常終了させてください。 | |
Score : 500 points
Problem Statement
This is an interactive task, where your and the judge's programs interact via Standard Input and Output.
You and the judge will follow the procedure below. The procedure consists of phases 1 and 2; phase 1 is immediately followed by phase 2.
(Phase 1)
- The judge decides an integer N between 1 and 10^9 (inclusive), which is hidden.
- You print an integer M between 1 and 110 (inclusive).
- You also print an integer sequence A=(A_1,A_2,\ldots,A_M) of length M such that 1 \leq A_i \leq M for all i = 1, 2, \ldots, M.
(Phase 2)
- The judge gives you an integer sequence B=(B_1,B_2,\ldots,B_M) of length M. Here, B_i = f^N(i). f(i) is defined by f(i)=A_i for all integers i between 1 and M (inclusive), and f^N(i) is the integer resulting from replacing i with f(i) N times.
- Based on the given B, you identify the integer N that the judge has decided, and print N.
After the procedure above, terminate the program immediately to be judged correct.
Constraints
- N is an integer between 1 and 10^9 (inclusive).
Input and Output
This is an interactive task, where your and the judge's programs interact via Standard Input and Output.
(Phase 1)
- First, print an integer M between 1 and 110 (inclusive). It must be followed by a newline.
M
- Then, print a sequence A=(A_1,A_2,\ldots,A_M) of length M consisting of integers between 1 and M (inclusive), with spaces in between. It must be followed by a newline.
A_1 A_2 \ldots A_M
(Phase 2)
- First, an integer sequence B=(B_1,B_2,\ldots,B_M) of length M is given from the input.
B_1 B_2 \ldots B_M
- Find the integer N and print it. It must be followed by a newline.
N
If you print something illegal, the judge prints -1
. In that case, your submission is already considered incorrect. Since the judge program terminates at this point, it is desirable that your program terminates too.
Notes
- After each output, add a newline and then flush Standard Output. Otherwise, you may get a TLE verdict.
- If an invalid output is printed during the interaction, or if the program terminates halfway, the verdict will be indeterminate.
- After you print the answer (or you receive
-1
), immediately terminate the program normally. Otherwise, the verdict will be indeterminate. - Note that an excessive newline is also considered an invalid input.
Sample Interaction
The following is a sample interaction with N = 2.
Input | Output | Description |
---|---|---|
The judge has decided that N=2. N is hidden: it is not given as an input. | ||
4 |
You print M. | |
2 3 4 4 |
You print A=(2,3,4,4). | |
3 4 4 4 |
f^2(1)=3,f^2(2)=4,f^2(3)=4, and f^2(4)=4, so the judge gives B=(3,4,4,4) to your program. | |
2 |
Based on B, you have identified that N=2. Print N and terminate the program normally. | |