Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)
B
Mickey Mouse Constructive
Codeforces
1100
原题
← AC1 →
翻译中…

Given an array $a$, let $f(a)$ be the number of ways to partition $a$ into one or more subarrays$^{\text{∗}}$ such that:

翻译中…
  • Each element appears in exactly one subarray.
  • All subarrays have the same sum.
翻译中…

For example, if $a=[1,1]$, then $f(a)=2$, because there are two such ways to partition $[1,1]$:

翻译中…
  • $[1,1]$, where the only subarray has sum $2$.
  • $[1]+[1]$, where both subarrays have sum $1$.
翻译中…

You are given two integers $x$ and $y$. Find the minimum value of $f(a)$ over all arrays $a$ of length $x+y$, consisting of $x$ copies of the number $1$, and $y$ copies of the number $-1$ in some order. Since this answer may be large, output the answer modulo $676\,767\,677$. Additionally, you should construct one array that achieves this minimal value.

翻译中…

$^{\text{∗}}$An array $b$ is a subarray of an array $c$ if $b$ can be obtained from $c$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $x$ and $y$ ($0 \leq x,y \leq 2\cdot 10^5$). It is guaranteed that $x+y \geq 1$.

翻译中…

It is guaranteed that the sum of $x$ over all test cases does not exceed $2\cdot 10^5$, and the sum of $y$ over all test cases does not exceed $2\cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output two lines: the minimum value of $f(a)$ over all valid arrays $a$ modulo $676\,767\,677$, and an example of an array that achieves the minimal result. Note you are minimizing $f(a)$, and taking that minimum value modulo $676\,767\,677$, not finding the minimal possible result of $f(a)$ mod $676\,767\,677$.

翻译中…

Note

翻译中…

In the first test case, $x=2$ and $y=0$. The only possible array is $a=[1,1]$, with $f(a)=2$ as explained above.

翻译中…

In the second case, $x=1$ and $y=1$. One possible array that minimizes $f(a)$ is $a=[1,-1]$, where $f(a)=1$ (as the only way to partition into subarrays with all subarrays having equal sum is $[[1,-1]]$).

翻译中…

样例

Input #1
4
2 0
1 1
6 7
1 3
Output #1
2
1 1
1
1 -1
1
-1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1
2
-1 -1 -1 1
InputCopy OutputCopy
题目信息
题号
2211B
时间限制
1.5 s
内存限制
256 MB
标签
构造
动态规划
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。