codeforces-scrape

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

1348B.md (2613B)


      1 Source: https://codeforces.com/problemset/problem/1348/B
      2 
      3 B. Phoenix and Beauty
      4 
      5 time limit per test
      6 
      7 2 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 Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
     22 
     23 Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
     24 
     25 Input
     26 
     27 The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
     28 
     29 The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
     30 
     31 The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
     32 
     33 Output
     34 
     35 For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
     36 
     37 The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
     38 
     39 The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
     40 
     41 If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 4
     49 4 2
     50 1 2 2 1
     51 4 3
     52 1 2 2 1
     53 3 2
     54 1 2 3
     55 4 4
     56 4 3 4 2
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 5
     63 1 2 1 2 1
     64 4
     65 1 2 2 1
     66 -1
     67 7
     68 4 3 2 1 4 3 2
     69 ```
     70 
     71 Note
     72 
     73 In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example:
     74 
     75 * $2, 1, 2, 1, 2, 1$
     76 * $1, 2, 1, 2, 1, 2$
     77 
     78 In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
     79 
     80 In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
     81 
     82 In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.