実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
長さ N の数列 A=(A_1,A_2,\ldots,A_N) および正整数 P,Q,R,S が与えられます。
ここで、P,Q,R,S は、1\leq P\leq Q<R\leq S \leq N および Q-P=S-R をみたしています。
数列 A の P 番目から Q 番目の項までと R 番目から S 番目の項までを入れ替えた数列を B=(B_1, B_2,\ldots, B_N) とします。
数列 B を出力してください。
制約
- 1\leq N \leq 100
- 1\leq A_i\leq 100
- 1\leq P\leq Q<R\leq S \leq N
- Q-P=S-R
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N P Q R S A_1 A_2 \ldots A_N
出力
B_1, B_2,\ldots, B_N を空白区切りで出力せよ。
入力例 1
8 1 3 5 7 1 2 3 4 5 6 7 8
出力例 1
5 6 7 4 1 2 3 8
数列 A=(1,2,3,4,5,6,7,8) の 1 番目から 3 番目の項 (1,2,3) と 5 番目から 7 番目までの項 (5,6,7) を 入れ替えると, B=(5,6,7,4,1,2,3,8) となります。 よってこれを空白区切りで出力します。
入力例 2
5 2 3 4 5 2 2 1 1 1
出力例 2
2 1 1 2 1
数列には同じ整数が複数回現れる事もあります。
入力例 3
2 1 1 2 2 50 100
出力例 3
100 50
入力例 4
10 2 4 7 9 22 75 26 45 72 81 47 29 97 2
出力例 4
22 47 29 97 72 81 75 26 45 2
Score : 100 points
Problem Statement
You are given a sequence A=(A_1,A_2,\ldots,A_N) of length N and positive integers P,Q,R, and S.
Here, P,Q,R, and S satisfy 1\leq P\leq Q<R\leq S \leq N and Q-P=S-R.
Let B=(B_1, B_2,\ldots, B_N) be the sequence obtained by swapping the P-th through Q-th terms and the R-th through S-th terms of A.
Print the sequence B.
Constraints
- 1\leq N \leq 100
- 1\leq A_i\leq 100
- 1\leq P\leq Q<R\leq S \leq N
- Q-P=S-R
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N P Q R S A_1 A_2 \ldots A_N
Output
Print B_1, B_2,\ldots, B_N, with spaces in between.
Sample Input 1
8 1 3 5 7 1 2 3 4 5 6 7 8
Sample Output 1
5 6 7 4 1 2 3 8
Swapping the 1-st through 3-rd terms (1,2,3) and the 5-th through 7-th terms (5,6,7) of the sequence A=(1,2,3,4,5,6,7,8) results in B=(5,6,7,4,1,2,3,8), which should be printed with spaces in between.
Sample Input 2
5 2 3 4 5 2 2 1 1 1
Sample Output 2
2 1 1 2 1
The same integer may occur multiple times in the sequence.
Sample Input 3
2 1 1 2 2 50 100
Sample Output 3
100 50
Sample Input 4
10 2 4 7 9 22 75 26 45 72 81 47 29 97 2
Sample Output 4
22 47 29 97 72 81 75 26 45 2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
正の整数 X について、レベル X の 龍文字列 とは、1 個の L, X 個の o, 1 個の n, 1 個の g をこの順に並べた長さ (X+3) の文字列です。
正の整数 N が与えられるので、レベル N の龍文字列を出力してください。
大文字と小文字は区別されることに注意してください。
制約
- 1\leq N\leq 2024
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
レベル N の龍文字列を出力せよ。
入力例 1
3
出力例 1
Looong
1 個の L, 3 個の o, 1 個の n, 1 個の g をこの順に並べた文字列は Looong です。
入力例 2
1
出力例 2
Long
Score: 100 points
Problem Statement
For a positive integer X, the Dragon String of level X is a string of length (X+3) formed by one L, X occurrences of o, one n, and one g arranged in this order.
You are given a positive integer N. Print the Dragon String of level N.
Note that uppercase and lowercase letters are distinguished.
Constraints
- 1 \leq N \leq 2024
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the Dragon String of level N.
Sample Input 1
3
Sample Output 1
Looong
Arranging one L, three os, one n, and one g in this order yields Looong.
Sample Input 2
1
Sample Output 2
Long
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
正整数 x に対して、f(x) を x の十進表記における各桁の和として定義します。例えば、f(123) = 1 + 2 + 3 = 6 です。
無限数列 A = (A_0, A_1, A_2, \ldots) を以下の式により定義します。
- A_0 = 1
- i \geq 1 のとき A_i = \displaystyle\sum_{j = 0}^{i - 1} f(A_j)
正整数 N が与えられます。A_N の値を求めてください。
制約
- N は 1 以上 100 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
6
出力例 1
23
- A_0 = 1
- A_1 = f(A_0) = 1
- A_2 = f(A_0) + f(A_1) = 2
- A_3 = f(A_0) + f(A_1) + f(A_2) = 4
- A_4 = f(A_0) + f(A_1) + f(A_2) + f(A_3) = 8
- A_5 = f(A_0) + f(A_1) + f(A_2) + f(A_3) + f(A_4) = 16
- A_6 = f(A_0) + f(A_1) + f(A_2) + f(A_3) + f(A_4) + f(A_5) = 23
であるため、A_6 = 23 です。
入力例 2
45
出力例 2
427
Score : 200 points
Problem Statement
For a positive integer x, define f(x) as the sum of the digits in the decimal representation of x. For example, f(123) = 1 + 2 + 3 = 6.
Define an infinite sequence A = (A_0, A_1, A_2, \ldots) by the following formula:
- A_0 = 1
- For i \geq 1, A_i = \displaystyle\sum_{j = 0}^{i - 1} f(A_j)
You are given a positive integer N. Find the value of A_N.
Constraints
- N is an integer between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
6
Sample Output 1
23
- A_0 = 1
- A_1 = f(A_0) = 1
- A_2 = f(A_0) + f(A_1) = 2
- A_3 = f(A_0) + f(A_1) + f(A_2) = 4
- A_4 = f(A_0) + f(A_1) + f(A_2) + f(A_3) = 8
- A_5 = f(A_0) + f(A_1) + f(A_2) + f(A_3) + f(A_4) = 16
- A_6 = f(A_0) + f(A_1) + f(A_2) + f(A_3) + f(A_4) + f(A_5) = 23
Thus, A_6 = 23.
Sample Input 2
45
Sample Output 2
427
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S, T が与えられます。S の長さは N、T の長さは M です。(N \leq M が制約で保証されています)
S が T の 接頭辞 であるとは、T のはじめ N 文字からなる文字列が S と一致することを言います。
S が T の 接尾辞 であるとは、T の後ろ N 文字からなる文字列が S と一致することを言います。
S が T の接頭辞であり、かつ接尾辞でもある場合は 0 を、
S が T の接頭辞であるが、接尾辞でない場合は 1 を、
S が T の接尾辞であるが、接頭辞でない場合は 2 を、
S が T の接頭辞でも接尾辞でもない場合は 3 を出力してください。
制約
- 1 \leq N \leq M \leq 100
- S は英小文字からなる長さ N の文字列
- T は英小文字からなる長さ M の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S T
出力
問題文の指示に従って答えを出力せよ。
入力例 1
3 7 abc abcdefg
出力例 1
1
S は T の接頭辞ですが接尾辞ではありません。よって 1 を出力します。
入力例 2
3 4 abc aabc
出力例 2
2
S は T の接尾辞ですが接頭辞ではありません。
入力例 3
3 3 abc xyz
出力例 3
3
S は T の接頭辞でも接尾辞でもありません。
入力例 4
3 3 aaa aaa
出力例 4
0
S と T が完全に一致する場合もあります。この場合、S は T の接頭辞であり、かつ接尾辞でもあります。
Score : 200 points
Problem Statement
You are given two strings S and T consisting of lowercase English letters. The lengths of S and T are N and M, respectively. (The constraints guarantee that N \leq M.)
S is said to be a prefix of T when the first N characters of T coincide S.
S is said to be a suffix of T when the last N characters of T coincide S.
If S is both a prefix and a suffix of T, print 0;
If S is a prefix of T but not a suffix, print 1;
If S is a suffix of T but not a prefix, print 2;
If S is neither a prefix nor a suffix of T, print 3.
Constraints
- 1 \leq N \leq M \leq 100
- S is a string of length N consisting of lowercase English letters.
- T is a string of length M consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N M S T
Output
Print the answer according to the instructions in the problem statement.
Sample Input 1
3 7 abc abcdefg
Sample Output 1
1
S is a prefix of T but not a suffix, so you should print 1.
Sample Input 2
3 4 abc aabc
Sample Output 2
2
S is a suffix of T but not a prefix.
Sample Input 3
3 3 abc xyz
Sample Output 3
3
S is neither a prefix nor a suffix of T.
Sample Input 4
3 3 aaa aaa
Sample Output 4
0
S and T may coincide, in which case S is both a prefix and a suffix of T.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1,2,\dots,N の番号が、辺には 1,2,\dots,M の番号がつけられており、辺 i は頂点 A_i と頂点 B_i を結んでいます。
このグラフがサイクルグラフであるか判定してください。
単純無向グラフとは
単純無向グラフとは、自己ループや多重辺を含まず、辺に向きの無いグラフのことをいいます。
サイクルグラフとは
頂点に 1, 2, \dots, N の番号が付けられた N 頂点のグラフがサイクルグラフであるとは、(1, 2, \dots, N) を並べ変えて得られる数列 (v_1, v_2, \dots, v_N) であって、以下の条件を満たすものが存在することをいいます。
制約
- 3\leq N \leq 2\times 10^5
- 0 \leq M \leq 2\times 10^5
- 1 \leq A_i, B_i \leq N
- 与えられるグラフは単純
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 \vdots A_M B_M
出力
与えられたグラフがサイクルグラフであるなら Yes、そうでないなら No と出力せよ。
入力例 1
4 4 2 4 3 1 4 1 2 3
出力例 1
Yes
与えられたグラフは以下の通りであり、これはサイクルグラフです。

入力例 2
4 6 1 2 1 3 1 4 2 3 2 4 3 4
出力例 2
No
与えられたグラフは以下の通りであり、これはサイクルグラフではありません。

Score : 300 points
Problem Statement
You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1,2,\dots,N and the edges are numbered 1,2,\dots,M. Edge i connects vertices A_i and B_i.
Determine whether this graph is a cycle graph.
Definition of simple undirected graph
A simple undirected graph is a graph with undirected edges without self-loops or multi-edges.
Definition of cycle graph
An N-vertex graph with vertices labeled 1,2,\dots,N is a cycle graph when there exists a permutation (v_1,v_2,\dots,v_N) of (1,2,\dots,N) such that:
Constraints
- 3 \le N \le 2\times 10^5
- 0 \le M \le 2\times 10^5
- 1 \le A_i, B_i \le N
- The given graph is simple.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 \vdots A_M B_M
Output
Output Yes if the given graph is a cycle graph; otherwise, print No.
Sample Input 1
4 4 2 4 3 1 4 1 2 3
Sample Output 1
Yes
The given graph is as follows, and this is a cycle graph.

Sample Input 2
4 6 1 2 1 3 1 4 2 3 2 4 3 4
Sample Output 2
No
The given graph is as follows, and this is not a cycle graph.

実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
空の列と、N 個のボールがあります。i 個目 (1\leq i\leq N) のボールの大きさは 2^{A_i} です。
これから N 回の操作を行います。
i 回目の操作では、i 個目のボールを列の一番右に付け加えた後、次の手順を繰り返します。
- 列にあるボールが 1 つ以下ならば操作を終了する。
- 列にあるボールのうち右から 1 番目のものと 2 番目のものの大きさが 異なる ならば操作を終了する。
- 列にあるボールのうち右から 1 番目のものと 2 番目のものの大きさが 等しい ならば、2 つのボールを取り除き、「取り除かれた 2 つのボールの大きさの和」の大きさのボール 1 つを列の一番右に付け加える。その後、1. に戻り、手順を繰り返す。
N 回の操作の後で、列にあるボールの数を求めてください。
制約
- 1\leq N \leq 2\times 10^5
- 0\leq A_i\leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
N 回の操作の後で、列にあるボールの数を出力せよ。
入力例 1
7 2 1 1 3 5 3 3
出力例 1
3
操作は次のように行われます。
- 1 回目の操作の後、列にあるボールは 1 つで、大きさは 2^2 です。
- 2 回目の操作の後、列にあるボールは 2 つで、大きさは順に 2^2, 2^1 です。
- 3 回目の操作の後、列にあるボールは 1 つで、大きさは 2^3 です。これは次のようにして得ることができます。
- 3 回目の操作において 3 個目のボールを付け加えたとき、列にあるボールの大きさは順に 2^2,2^1,2^1 となります。
- 右から 1 番目のボールと 2 番目のボールの大きさが等しいため、これらのボールが取り除かれ、大きさが 2^1+2^1=2^2 のボールが追加されます。このとき、列にあるボールの大きさは 2^2, 2^2 となります。
- さらに、再び右から 1 番目のボールと 2 番目のボールの大きさが等しいため、これらのボールが取り除かれ、大きさが 2^2+2^2=2^3 のボールが追加され、列にあるボールの大きさは 2^3 となります。
- 4 回目の操作の後、列にあるボールは 1 つで、大きさは 2^4 です。
- 5 回目の操作の後、列にあるボールは 2 つで、大きさは順に 2^4, 2^5 です。
- 6 回目の操作の後、列にあるボールは 3 つで、大きさは順に 2^4, 2^5, 2^3 です。
- 7 回目の操作の後、列にあるボールは 3 つで、大きさは順に 2^4, 2^5, 2^4 です。
よって、最後に列にあるボールの数である 3 を出力します。
入力例 2
5 0 0 0 1 2
出力例 2
4
操作は次のように行われます。
- 1 回目の操作の後、列にあるボールは 1 つで、大きさは 2^0 です。
- 2 回目の操作の後、列にあるボールは 1 つで、大きさは 2^1 です。
- 3 回目の操作の後、列にあるボールは 2 つで、大きさは順に 2^1, 2^0 です。
- 4 回目の操作の後、列にあるボールは 3 つで、大きさは順に 2^1, 2^0, 2^1 です。
- 5 回目の操作の後、列にあるボールは 4 つで、大きさは順に 2^1, 2^0, 2^1, 2^2 です。
よって、最後に列にあるボールの数である 4 を出力します。
Score: 250 points
Problem Statement
You have an empty sequence and N balls. The size of the i-th ball (1 \leq i \leq N) is 2^{A_i}.
You will perform N operations.
In the i-th operation, you add the i-th ball to the right end of the sequence, and repeat the following steps:
- If the sequence has one or fewer balls, end the operation.
- If the rightmost ball and the second rightmost ball in the sequence have different sizes, end the operation.
- If the rightmost ball and the second rightmost ball in the sequence have the same size, remove these two balls and add a new ball to the right end of the sequence with a size equal to the sum of the sizes of the two removed balls. Then, go back to step 1 and repeat the process.
Determine the number of balls remaining in the sequence after the N operations.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the number of balls in the sequence after the N operations.
Sample Input 1
7 2 1 1 3 5 3 3
Sample Output 1
3
The operations proceed as follows:
- After the first operation, the sequence has one ball, of size 2^2.
- After the second operation, the sequence has two balls, of sizes 2^2 and 2^1 in order.
- After the third operation, the sequence has one ball, of size 2^3. This is obtained as follows:
- When the third ball is added during the third operation, the sequence has balls of sizes 2^2, 2^1, 2^1 in order.
- The first and second balls from the right have the same size, so these balls are removed, and a ball of size 2^1 + 2^1 = 2^2 is added. Now, the sequence has balls of sizes 2^2, 2^2.
- Again, the first and second balls from the right have the same size, so these balls are removed, and a ball of size 2^2 + 2^2 = 2^3 is added, leaving the sequence with a ball of size 2^3.
- After the fourth operation, the sequence has one ball, of size 2^4.
- After the fifth operation, the sequence has two balls, of sizes 2^4 and 2^5 in order.
- After the sixth operation, the sequence has three balls, of sizes 2^4, 2^5, 2^3 in order.
- After the seventh operation, the sequence has three balls, of sizes 2^4, 2^5, 2^4 in order.
Therefore, you should print 3, the final number of balls in the sequence.
Sample Input 2
5 0 0 0 1 2
Sample Output 2
4
The operations proceed as follows:
- After the first operation, the sequence has one ball, of size 2^0.
- After the second operation, the sequence has one ball, of size 2^1.
- After the third operation, the sequence has two balls, of sizes 2^1 and 2^0 in order.
- After the fourth operation, the sequence has three balls, of sizes 2^1, 2^0, 2^1 in order.
- After the fifth operation, the sequence has four balls, of sizes 2^1, 2^0, 2^1, 2^2 in order.
Therefore, you should print 4, the final number of balls in the sequence.
実行時間制限: 2 sec / メモリ制限: 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. |
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
高橋君は N 曲からなるプレイリストを持っています。
曲 i (1 \leq i \leq N) の長さは T_i 秒です。
高橋君は時刻 0 にプレイリストのランダム再生を開始しました。
ランダム再生では、N 曲の中から等確率で 1 つを選びその曲を最後まで再生することが繰り返されます。 ここで、曲の再生は休みなく行われ、1 つの曲が終わったらすぐに次に選ばれた曲が始まります。 また、同じ曲が連続して選ばれる事もあります。
時刻 0 から (X+0.5) 秒後に曲 1 が再生されている確率を \text{mod}998244353 で求めてください。
確率 \text{mod } 998244353 の定義
この問題で求める確率は必ず有理数になることが証明できます。 また、この問題の制約下では、求める確率を既約分数 \frac{y}{x} で表したときに x が 998244353 で割り切れないことが保証されます。
このとき xz \equiv y \pmod{998244353} を満たすような 0 以上 998244352 以下の整数 z が一意に定まります。この z を答えてください。
制約
- 2 \leq N\leq 10^3
- 0 \leq X\leq 10^4
- 1 \leq T_i\leq 10^4
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X T_1 T_2 \ldots T_N
出力
時刻 0 から (X+0.5) 秒後にプレイリストの 1 番目の曲が再生されている確率を \text{mod}998244353 で出力せよ。
入力例 1
3 6 3 5 6
出力例 1
369720131
時刻 0 から 6.5 秒後に曲 1 が流れているパターンとしてあり得るのは、
- 曲 1 \to 曲 1 \to 曲 1
- 曲 2 \to 曲 1
- 曲 3 \to 曲 1
の順で音楽が再生された場合であり、これらのいずれかが起こる確率は \frac{7}{27} となります。
369720131\times 27\equiv 7 \pmod{998244353} であるため、369720131 を出力します。
入力例 2
5 0 1 2 1 2 1
出力例 2
598946612
時刻 0 から 0.5 秒後には最初に再生された曲が再生されているため、求める確率は \frac{1}{5} となります。
同じ長さの異なる曲が存在することがあることに注意してください。
入力例 3
5 10000 1 2 3 4 5
出力例 3
586965467
Score : 450 points
Problem Statement
Takahashi has a playlist with N songs.
Song i (1 \leq i \leq N) lasts T_i seconds.
Takahashi has started random play of the playlist at time 0.
Random play repeats the following: choose one song from the N songs with equal probability and play that song to the end. Here, songs are played continuously: once a song ends, the next chosen song starts immediately. The same song can be chosen consecutively.
Find the probability that song 1 is being played (X + 0.5) seconds after time 0, modulo 998244353.
How to print a probability modulo 998244353
It can be proved that the probability to be found in this problem is always a rational number. Also, the constraints of this problem guarantee that when the probability to be found is expressed as an irreducible fraction \frac{y}{x}, x is not divisible by 998244353.
Then, there is a unique integer z between 0 and 998244352, inclusive, such that xz \equiv y \pmod{998244353}. Report this z.
Constraints
- 2 \leq N\leq 10^3
- 0 \leq X\leq 10^4
- 1 \leq T_i\leq 10^4
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X T_1 T_2 \ldots T_N
Output
Print the probability, modulo 998244353, that the first song in the playlist is being played (X+0.5) seconds after time 0.
Sample Input 1
3 6 3 5 6
Sample Output 1
369720131
Song 1 will be playing 6.5 seconds after time 0 if songs are played in one of the following orders.
- Song 1 \to Song 1 \to Song 1
- Song 2 \to Song 1
- Song 3 \to Song 1
The probability that one of these occurs is \frac{7}{27}.
We have 369720131\times 27\equiv 7 \pmod{998244353}, so you should print 369720131.
Sample Input 2
5 0 1 2 1 2 1
Sample Output 2
598946612
0.5 seconds after time 0, the first song to be played is still playing, so the sought probability is \frac{1}{5}.
Note that different songs may have the same length.
Sample Input 3
5 10000 1 2 3 4 5
Sample Output 3
586965467
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
頂点に 1 から N の番号がついた N 頂点 N 辺の連結な単純無向グラフ G が与えられます。i 番目の辺は頂点 u_i と頂点 v_i を双方向に結んでいます。
以下の Q 個のクエリに答えてください。
- 頂点 x_i から頂点 y_i に向かう単純パス(同じ頂点を 2 度通らないパス)が一意に定まるか判定せよ。
制約
- 3 \leq N \leq 2 \times 10^5
- 1 \leq u_i < v_i\leq N
- i \neq j ならば (u_i,v_i) \neq (u_j,v_j)
- G は N 頂点 N 辺の連結な単純無向グラフ
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq x_i < y_i\leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N u_1 v_1 u_2 v_2 \vdots u_N v_N Q x_1 y_1 x_2 y_2 \vdots x_Q y_Q
出力
Q 行出力せよ。
i\ (1 \leq i \leq Q) 行目には、頂点 x_i から頂点 y_i に向かう単純パスが一意に定まる場合 Yes、そうでない場合 No を出力せよ。
入力例 1
5 1 2 2 3 1 3 1 4 2 5 3 1 2 1 4 1 5
出力例 1
No Yes No
頂点 1 から 2 に向かう単純パスは (1,2),(1,3,2) と一意に定まらないので、 1 個目のクエリの答えは No です。
頂点 1 から 4 に向かう単純パスは (1,4) と一意に定まるので、2 個目のクエリの答えは Yes です。
頂点 1 から 5 に向かう単純パスは (1,2,5),(1,3,2,5) と一意に定まらないので、3 個目のクエリの答えは No です。
入力例 2
10 3 5 5 7 4 8 2 9 1 2 7 9 1 6 4 10 2 5 2 10 10 1 8 6 9 8 10 6 8 3 10 3 9 1 10 5 8 1 10 7 8
出力例 2
Yes No Yes Yes No No Yes No Yes No
Score : 500 points
Problem Statement
You are given a connected simple undirected graph G with N vertices numbered 1 to N and N edges. The i-th edge connects Vertex u_i and Vertex v_i bidirectionally.
Answer the following Q queries.
- Determine whether there is a unique simple path from Vertex x_i to Vertex y_i (a simple path is a path without repetition of vertices).
Constraints
- 3 \leq N \leq 2 \times 10^5
- 1 \leq u_i < v_i\leq N
- (u_i,v_i) \neq (u_j,v_j) if i \neq j.
- G is a connected simple undirected graph with N vertices and N edges.
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq x_i < y_i\leq N
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N u_1 v_1 u_2 v_2 \vdots u_N v_N Q x_1 y_1 x_2 y_2 \vdots x_Q y_Q
Output
Print Q lines.
The i-th line (1 \leq i \leq Q) should contain Yes if there is a unique simple path from Vertex x_i to Vertex y_i, and No otherwise.
Sample Input 1
5 1 2 2 3 1 3 1 4 2 5 3 1 2 1 4 1 5
Sample Output 1
No Yes No
The simple paths from Vertex 1 to 2 are (1,2) and (1,3,2), which are not unique, so the answer to the first query is No.
The simple path from Vertex 1 to 4 is (1,4), which is unique, so the answer to the second query is Yes.
The simple paths from Vertex 1 to 5 are (1,2,5) and (1,3,2,5), which are not unique, so the answer to the third query is No.
Sample Input 2
10 3 5 5 7 4 8 2 9 1 2 7 9 1 6 4 10 2 5 2 10 10 1 8 6 9 8 10 6 8 3 10 3 9 1 10 5 8 1 10 7 8
Sample Output 2
Yes No Yes Yes No No Yes No Yes No