codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

2211B.md (2451B)


      1 Source: https://codeforces.com/problemset/problem/2211/B
      2 
      3 B. Mickey Mouse Constructive
      4 
      5 time limit per test
      6 
      7 1.5 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Given an array $a$, let $f(a)$ be the number of ways to partition $a$ into one or more subarrays$^{\text{∗}}$ such that:
     22 
     23 * Each element appears in exactly one subarray.
     24 * All subarrays have the same sum.
     25 
     26 For example, if $a=[1,1]$, then $f(a)=2$, because there are two such ways to partition $[1,1]$:
     27 
     28 * $[1,1]$, where the only subarray has sum $2$.
     29 * $[1]+[1]$, where both subarrays have sum $1$.
     30 
     31 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.
     32 
     33 $^{\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.
     34 
     35 Input
     36 
     37 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.
     38 
     39 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$.
     40 
     41 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$.
     42 
     43 Output
     44 
     45 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$.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 4
     53 
     54 2 0
     55 
     56 1 1
     57 
     58 6 7
     59 
     60 1 3
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 2
     67 1 1
     68 1
     69 1 -1
     70 1
     71 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1
     72 2
     73 -1 -1 -1 1
     74 ```
     75 
     76 Note
     77 
     78 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.
     79 
     80 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]]$).