Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder Beginner Contest は、今回で 214 回目の開催となりました。
今までの AtCoder Beginner Contest において、出題される問題数は次のように変化しました。
- 1 回目から 125 回目までは 4 問
- 126 回目から 211 回目までは 6 問
- 212 回目から 214 回目までは 8 問
N 回目の AtCoder Beginner Contest において出題された問題数を求めてください。
制約
- 1 \leq N \leq 214
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
214
出力例 1
8
入力例 2
1
出力例 2
4
入力例 3
126
出力例 3
6
Score : 100 points
Problem Statement
This is the 214-th AtCoder Beginner Contest (ABC).
The ABCs so far have had the following number of problems.
- The 1-st through 125-th ABCs had 4 problems each.
- The 126-th through 211-th ABCs had 6 problems each.
- The 212-th through 214-th ABCs have 8 problems each.
Find the number of problems in the N-th ABC.
Constraints
- 1 \leq N \leq 214
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
214
Sample Output 1
8
Sample Input 2
1
Sample Output 2
4
Sample Input 3
126
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正整数 N が与えられます。
1 以上 N 以下の整数をすべて足し合わせた値 1+2+\cdots+N を出力してください。
制約
- 1 \leq N \leq 100
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
1 以上 N 以下の整数をすべて足し合わせた値を出力せよ。
入力例 1
5
出力例 1
15
1+2+3+4+5=15 のため、15 を出力します。
入力例 2
1
出力例 2
1
入力例 3
29
出力例 3
435
Score : 100 points
Problem Statement
You are given a positive integer N.
Output the sum of all integers from 1 to N, that is, 1+2+\cdots+N.
Constraints
- 1 \leq N \leq 100
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Output the sum of all integers from 1 to N.
Sample Input 1
5
Sample Output 1
15
Since 1+2+3+4+5=15, output 15.
Sample Input 2
1
Sample Output 2
1
Sample Input 3
29
Sample Output 3
435
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英大文字と英小文字からなる文字列のうち、以下の条件を全て満たすものを素晴らしい文字列ということとします。
- 英大文字が文字列の中に現れる。
- 英小文字が文字列の中に現れる。
- 全ての文字が相異なる。
例えば、AtCoder や Aa は素晴らしい文字列ですが、atcoder や Perfect は素晴らしい文字列ではありません。
文字列 S が与えられるので、S が素晴らしい文字列か判定してください。
制約
- 1 \le |S| \le 100
- S は英大文字と英小文字からなる文字列である。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が素晴らしい文字列ならば Yes を、そうでないならば No を出力せよ。
入力例 1
AtCoder
出力例 1
Yes
AtCoder は、英大文字が含まれ、英小文字も含まれ、かつ全ての文字が相異なるため素晴らしい文字列です。
入力例 2
Aa
出力例 2
Yes
A と a は違う文字であることに注意してください。この文字列は素晴らしい文字列です。
入力例 3
atcoder
出力例 3
No
英大文字が含まれていないため、素晴らしい文字列ではありません。
入力例 4
Perfect
出力例 4
No
2 文字目と 5 文字目が等しいため、素晴らしい文字列ではありません。
Score : 200 points
Problem Statement
Let us call a string consisting of uppercase and lowercase English alphabets a wonderful string if all of the following conditions are satisfied:
- The string contains an uppercase English alphabet.
- The string contains a lowercase English alphabet.
- All characters in the string are pairwise distinct.
For example, AtCoder and Aa are wonderful strings, while atcoder and Perfect are not.
Given a string S, determine if S is a wonderful string.
Constraints
- 1 \le |S| \le 100
- S is a string consisting of uppercase and lowercase English alphabets.
Input
Input is given from Standard Input in the following format:
S
Output
If S is a wonderful string, print Yes; otherwise, print No.
Sample Input 1
AtCoder
Sample Output 1
Yes
AtCoder is a wonderful string because it contains an uppercase English alphabet, a lowercase English alphabet, and all characters in the string are pairwise distinct.
Sample Input 2
Aa
Sample Output 2
Yes
Note that A and a are different characters. This string is a wonderful string.
Sample Input 3
atcoder
Sample Output 3
No
It is not a wonderful string because it does not contain an uppercase English alphabet.
Sample Input 4
Perfect
Sample Output 4
No
It is not a wonderful string because the 2-nd and the 5-th characters are the same.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は容量が G ml のグラスと、容量が M ml のマグカップを 1 つずつ持っています。
ここで、G,M は G<M をみたします。
最初、グラスとマグカップはいずれも空です。
以下の操作を K 回繰り返した後で、グラスとマグカップに水がそれぞれ何 ml ずつ入っているか求めてください。
- グラスが水で満たされているとき、すなわちグラスにちょうど G ml 入っているとき、グラスの水をすべて捨てる。
- そうでなく、マグカップが空であるとき、マグカップを水で満たす。
- 上のいずれでもないとき、マグカップが空になるかグラスが水で満たされるまで、マグカップからグラスに水を移す。
制約
- 1\leq K\leq 100
- 1\leq G<M\leq 1000
- G,M,K は整数
入力
入力は以下の形式で標準入力から与えられる。
K G M
出力
操作を K 回行った後で、グラスとマグカップに水がそれぞれ何 ml ずつ入っているか、この順に空白区切りで出力せよ。
入力例 1
5 300 500
出力例 1
200 500
操作は次の順で行われます。最初、グラスとマグカップはいずれも空です。
- マグカップを水で満たす。グラスには 0 ml, マグカップには 500 ml 入った状態になる。
- グラスが満たされるまでマグカップからグラスに水を移す。グラスには 300 ml, マグカップには 200 ml 入った状態になる。
- グラスの水をすべて捨てる。グラスには 0 ml, マグカップには 200 ml 入った状態になる。
- マグカップが空になるまでマグカップからグラスに水を移す。グラスには 200 ml, マグカップには 0 ml 入った状態になる。
- マグカップを水で満たす。グラスには 200 ml, マグカップには 500 ml 入った状態になる。
よって、5 回の操作の後でグラスには 200 ml, マグカップには 500 ml 入った状態になります。 ゆえに、200, 500 を空白区切りでこの順に出力します。
入力例 2
5 100 200
出力例 2
0 0
Score : 200 points
Problem Statement
AtCoder Inc. sells glasses and mugs.
Takahashi has a glass with a capacity of G milliliters and a mug with a capacity of M milliliters.
Here, G<M.
Initially, both the glass and the mug are empty.
After performing the following operation K times, determine how many milliliters of water are in the glass and the mug, respectively.
- When the glass is filled with water, that is, the glass contains exactly G milliliters of water, discard all the water from the glass.
- Otherwise, if the mug is empty, fill the mug with water.
- Otherwise, transfer water from the mug to the glass until the mug is empty or the glass is filled with water.
Constraints
- 1\leq K\leq 100
- 1\leq G<M\leq 1000
- G, M, and K are integers.
Input
The input is given from Standard Input in the following format:
K G M
Output
Print the amounts, in milliliters, of water in the glass and the mug, in this order, separated by a space, after performing the operation K times.
Sample Input 1
5 300 500
Sample Output 1
200 500
The operation will be performed as follows. Initially, both the glass and the mug are empty.
- Fill the mug with water. The glass has 0 milliliters, and the mug has 500 milliliters of water.
- Transfer water from the mug to the glass until the glass is filled. The glass has 300 milliliters, and the mug has 200 milliliters of water.
- Discard all the water from the glass. The glass has 0 milliliters, and the mug has 200 milliliters of water.
- Transfer water from the mug to the glass until the mug is empty. The glass has 200 milliliters, and the mug has 0 milliliters of water.
- Fill the mug with water. The glass has 200 milliliters, and the mug has 500 milliliters of water.
Thus, after five operations, the glass has 200 milliliters, and the mug has 500 milliliters of water. Hence, print 200 and 500 in this order, separated by a space.
Sample Input 2
5 100 200
Sample Output 2
0 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
長さ N の正整数列 A=(A_1,A_2,\dots,A_N) および正整数 K が与えられます。
1 以上 K 以下の整数のうち、A の中に一度も現れないものの総和を求めてください。
制約
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq 2\times 10^9
- 1\leq A_i \leq 2\times 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 5 1 6 3 1
出力例 1
11
1 以上 5 以下の整数のうち、A の中に一度も現れないものは 2,4,5 の 3 つです。
よって、それらの総和である 2+4+5=11 を出力します。
入力例 2
1 3 346
出力例 2
6
入力例 3
10 158260522 877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739
出力例 3
12523196466007058
Score: 250 points
Problem Statement
You are given a sequence of positive integers A=(A_1,A_2,\dots,A_N) of length N and a positive integer K.
Find the sum of the integers between 1 and K, inclusive, that do not appear in the sequence A.
Constraints
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq 2\times 10^9
- 1\leq A_i \leq 2\times 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
4 5 1 6 3 1
Sample Output 1
11
Among the integers between 1 and 5, three numbers, 2, 4, and 5, do not appear in A.
Thus, print their sum: 2+4+5=11.
Sample Input 2
1 3 346
Sample Output 2
6
Sample Input 3
10 158260522 877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739
Sample Output 3
12523196466007058
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個の餅が小さいほうから順に並んでいます。 i 番目 (1\leq i\leq N) の餅の大きさは A _ i です。
2 つの餅 A,B の大きさをそれぞれ a,b としたとき、a が b の半分以下であるとき、かつそのときに限り、餅 A を餅 B の上に乗せて鏡餅を 1 つ作ることができます。
N 個の餅から 2 つの餅を選び、一方をもう一方の上に乗せることで鏡餅を 1 つ作ります。
何種類の鏡餅を作ることができるか求めてください。
ただし、鏡餅を構成する餅の大きさが同じでも、少なくとも一方が異なる餅であれば別の種類の鏡餅として数えます。
制約
- 2\leq N\leq 5\times 10 ^ 5
- 1\leq A _ i\leq 10 ^ 9\ (1\leq i\leq N)
- A _ i\leq A _ {i+1}\ (1\leq i\lt N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \cdots A _ N
出力
作ることができる鏡餅の種類数を出力せよ。
入力例 1
6 2 3 4 4 7 10
出力例 1
8
与えられた餅の大きさは以下のようになっています。

このとき、以下の 8 種類の鏡餅を作ることができます。

大きさ 4 の餅の上に大きさ 2 の餅を乗せた鏡餅や、大きさ 10 の餅の上に大きさ 4 の餅を乗せた鏡餅は 2 種類あることに注意してください。
入力例 2
3 387 388 389
出力例 2
0
鏡餅を 1 種類も作ることができない場合もあります。
入力例 3
32 1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641
出力例 3
388
Score : 300 points
Problem Statement
There are N mochi (rice cakes) arranged in ascending order of size. The size of the i-th mochi (1 \leq i \leq N) is A_i.
Given two mochi A and B, with sizes a and b respectively, you can make one kagamimochi (a stacked rice cake) by placing mochi A on top of mochi B if and only if a is at most half of b.
You choose two mochi out of the N mochi, and place one on top of the other to form one kagamimochi.
Find how many different kinds of kagamimochi can be made.
Two kagamimochi are distinguished if at least one of the mochi is different, even if the sizes of the mochi are the same.
Constraints
- 2 \leq N \leq 5 \times 10^5
- 1 \leq A_i \leq 10^9 \ (1 \leq i \leq N)
- A_i \leq A_{i+1} \ (1 \leq i < N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \cdots A_N
Output
Print the number of different kinds of kagamimochi that can be made.
Sample Input 1
6 2 3 4 4 7 10
Sample Output 1
8
The sizes of the given mochi are as follows:

In this case, you can make the following eight kinds of kagamimochi:

Note that there are two kinds of kagamimochi where a mochi of size 4 is topped by a mochi of size 2, and two kinds where a mochi of size 10 is topped by a mochi of size 4.
Sample Input 2
3 387 388 389
Sample Output 2
0
It is possible that you cannot make any kagamimochi.
Sample Input 3
32 1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641
Sample Output 3
388
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
頂点 1,2,\dots,N の N 頂点からなる木が与えられます。この木の辺のうち i 本目は頂点 U_i と頂点 V_i を結びます。
頂点 i には整数 A_i が書かれています。
全ての k=1,2,\dots,N について以下の問題に答えてください。
- 問題: 頂点 1 から頂点 k への単純なパス (同じ頂点を複数回通らないパス) に含まれる頂点について、同じ整数の書かれた異なる 2 頂点の組が存在すれば
Yes、そうでないならNoと答えよ。- なお、木上の 2 つの頂点を結ぶ単純なパスが一意に定まることは証明できる。
制約
- 入力は全て整数
- 2 \le N \le 2 \times 10^5
- 1 \le A_i \le 10^9
- 1 \le U_i, V_i \le N
- 与えられるグラフは木
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \dots A_N
U_1 V_1
U_2 V_2
\vdots
U_{N-1} V_{N-1}
出力
N 行出力せよ。
そのうち i 行目には、 k=i である場合の問題の答えを出力せよ。
入力例 1
5 1 3 2 1 2 1 2 1 3 3 4 3 5
出力例 1
No No No Yes Yes
- k=1 について、頂点 1 から頂点 1 へのパスに含まれるのは頂点 1 です。パスが 1 頂点のみで構成されるので、答えは
Noとなります。 - k=2 について、頂点 1 から頂点 2 へのパスに含まれるのは頂点 1,2 で、それぞれに書かれた整数は 1,3 です。よって、答えは
Noです。 - k=3 について、頂点 1 から頂点 3 へのパスに含まれるのは頂点 1,3 で、それぞれに書かれた整数は 1,2 です。よって、答えは
Noです。 - k=4 について、頂点 1 から頂点 4 へのパスに含まれるのは頂点 1,3,4 で、それぞれに書かれた整数は 1,2,1 です。パス内の頂点 1,4 に同じ整数 1 が書かれているので、答えは
Yesです。 - k=5 について、頂点 1 から頂点 5 へのパスに含まれるのは頂点 1,3,5 で、それぞれに書かれた整数は 1,2,2 です。パス内の頂点 3,5 に同じ整数 2 が書かれているので、答えは
Yesです。
入力例 2
2 1000000000 1000000000 2 1
出力例 2
No Yes
入力例 3
10 10 7 3 9 1 3 8 5 7 10 3 6 8 6 6 1 9 7 7 10 5 4 4 2 10 2 1 9
出力例 3
No Yes Yes Yes Yes No No No No Yes
Score : 400 points
Problem Statement
You are given a tree with N vertices numbered 1,2,\dots,N. The i-th edge connects vertices U_i and V_i.
Each vertex i has an integer A_i written on it.
Answer the following problem for all k=1,2,\dots,N.
- Problem: Among the vertices on the simple path (a path that does not visit the same vertex more than once) from vertex 1 to vertex k, if there exist two distinct vertices with the same integer written on them, output
Yes; otherwise, outputNo.- It can be proved that the simple path connecting two vertices on a tree is unique.
Constraints
- All input values are integers.
- 2 \le N \le 2 \times 10^5
- 1 \le A_i \le 10^9
- 1 \le U_i, V_i \le N
- The given graph is a tree.
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_N
U_1 V_1
U_2 V_2
\vdots
U_{N-1} V_{N-1}
Output
Output N lines.
The i-th line should contain the answer to the problem for k=i.
Sample Input 1
5 1 3 2 1 2 1 2 1 3 3 4 3 5
Sample Output 1
No No No Yes Yes
- For k=1: the path from vertex 1 to vertex 1 contains only vertex 1. Since the path consists of only one vertex, the answer is
No. - For k=2: the path from vertex 1 to vertex 2 contains vertices 1,2, with integers 1,3 written on them respectively. Thus, the answer is
No. - For k=3: the path from vertex 1 to vertex 3 contains vertices 1,3, with integers 1,2 written on them respectively. Thus, the answer is
No. - For k=4: the path from vertex 1 to vertex 4 contains vertices 1,3,4, with integers 1,2,1 written on them respectively. Since vertices 1 and 4 on the path have the same integer 1 written on them, the answer is
Yes. - For k=5: the path from vertex 1 to vertex 5 contains vertices 1,3,5, with integers 1,2,2 written on them respectively. Since vertices 3 and 5 on the path have the same integer 2 written on them, the answer is
Yes.
Sample Input 2
2 1000000000 1000000000 2 1
Sample Output 2
No Yes
Sample Input 3
10 10 7 3 9 1 3 8 5 7 10 3 6 8 6 6 1 9 7 7 10 5 4 4 2 10 2 1 9
Sample Output 3
No Yes Yes Yes Yes No No No No Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 頂点の木と、長さ M の数列 A=(A_1,\ldots,A_M)、整数 K が与えられます。
木の頂点には 1 から N の番号がつけられており、i 番目の辺は頂点 U_i と V_i を結んでいます。
この木の N-1 個の辺をそれぞれ赤か青のどちらかに塗ります。そのような方法は 2^{N-1} 通りありますが、そのうち次の条件を満たすような塗り方の個数を 998244353 で割った余りを求めてください。
条件:
最初、駒を頂点 A_1 におく。i=1,\ldots,M-1 の順に、駒を頂点 A_i から頂点 A_{i+1} まで、辺をたどって最短経路で動かす。
これらの操作を最後まで行ったとき、赤く塗られた辺を通過した回数を R、青く塗られた辺を通過した回数を B とすると、R-B=K である。
制約
- 2 \leq N \leq 1000
- 2 \leq M \leq 100
- |K| \leq 10^5
- 1 \leq A_i \leq N
- 1\leq U_i,V_i\leq N
- 与えられるグラフは木である
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M K
A_1 A_2 \ldots A_M
U_1 V_1
\vdots
U_{N-1} V_{N-1}
出力
答えを出力せよ。
入力例 1
4 5 0 2 3 2 1 4 1 2 2 3 3 4
出力例 1
2
1,3 番目の辺を赤く、2 番目の辺を青く塗ったとき、
- 頂点 2 から頂点 3 への移動で赤い辺を 0 回、青い辺を 1 回
- 頂点 3 から頂点 2 への移動で赤い辺を 0 回、青い辺を 1 回
- 頂点 2 から頂点 1 への移動で赤い辺を 1 回、青い辺を 0 回
- 頂点 1 から頂点 4 への移動で赤い辺を 2 回、青い辺を 1 回
それぞれ通過し、全体では赤い辺を 3 回、青い辺を 3 回通るため、条件を満たします。

この他、1,3 番目の辺を青く、2 番目の辺を赤く塗るときも条件を満たし、これら以外の塗り方は条件を満たさないため、答えは 2 通りです。
入力例 2
3 10 10000 1 2 1 2 1 2 2 1 1 2 1 2 1 3
出力例 2
0
条件を満たす塗り方が存在しないこともあります。
入力例 3
10 2 -1 1 10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
出力例 3
126
入力例 4
5 8 -1 1 4 1 4 2 1 3 5 1 2 4 1 3 1 1 5
出力例 4
2
Score : 500 points
Problem Statement
Given are a tree with N vertices, a sequence of M numbers A=(A_1,\ldots,A_M), and an integer K.
The vertices are numbered 1 through N, and the i-th edge connects Vertices U_i and V_i.
We will paint each of the N-1 edges of this tree red or blue. Among the 2^{N-1} such ways, find the number of ones that satisfies the following condition, modulo 998244353.
Condition:
Let us put a piece on Vertex A_1, and for each i=1,\ldots,M-1 in this order, move it from Vertex A_i to Vertex A_{i+1} along the edges in the shortest path. After all of these movements, R-B=K holds, where R and B are the numbers of times the piece traverses a red edge and a blue edge, respectively.
Constraints
- 2 \leq N \leq 1000
- 2 \leq M \leq 100
- |K| \leq 10^5
- 1 \leq A_i \leq N
- 1\leq U_i,V_i\leq N
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K
A_1 A_2 \ldots A_M
U_1 V_1
\vdots
U_{N-1} V_{N-1}
Output
Print the answer.
Sample Input 1
4 5 0 2 3 2 1 4 1 2 2 3 3 4
Sample Output 1
2
If we paint the 1-st and 3-rd edges red and the 2-nd edge blue, the piece will traverse the following numbers of red and blue edges:
- 0 red edges and 1 blue edge when moving from Vertex 2 to 3,
- 0 red edges and 1 blue edge when moving from Vertex 3 to 2,
- 1 red edge and 0 blue edges when moving from Vertex 2 to 1,
- 2 red edges and 1 blue edge when moving from Vertex 1 to 4,
for a total of 3 red edges and 3 blue edges, satisfying the condition.

Another way to satisfy the condition is to paint the 1-st and 3-rd edges blue and the 2-nd edge red. There is no other way to satisfy it, so the answer is 2.
Sample Input 2
3 10 10000 1 2 1 2 1 2 2 1 1 2 1 2 1 3
Sample Output 2
0
There may be no way to paint the tree to satisfy the condition.
Sample Input 3
10 2 -1 1 10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
Sample Output 3
126
Sample Input 4
5 8 -1 1 4 1 4 2 1 3 5 1 2 4 1 3 1 1 5
Sample Output 4
2
Time Limit: 2 sec / Memory Limit: 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. | |