CF2225G.Simple Problem

省选/NOI-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One day, Polycarp came up with the following simple problem: the numbers $ 0, 1, \ldots, n-1 $ are given. Is it possible to arrange them so that the absolute difference of every adjacent pair of numbers is divisible by at least one of the numbers $ k_1, k_2, \ldots, k_m $ ?

Polycarp spent a long time thinking about how to solve this problem and eventually realized that it is not so simple after all. Help him solve this problem.

输入格式

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

The first line of each test case contains two integers $ n $ and $ m $ ( $ 3 \leq n \leq 5 \cdot 10^{3} $ ; $ 1 \leq m \leq 10 $ ).

The second line of each test case contains $ m $ integers $ k_{i} $ ( $ 1 \leq k_i \leq \left\lfloor \frac{n}{3} \right\rfloor $ ).

Additional constraints on the input:

  • the sum of $ n $ over all test cases does not exceed $ 5 \cdot 10^{3} $ .

输出格式

For each test case, output one of the following:

  • -1 on a single line if no suitable arrangement exists;
  • $ n $ integers $ 0, 1, \ldots, n-1 $ satisfying the condition. If there are multiple answers, print any of them.

输入输出样例

  • 输入#1

    2
    10 2
    2 3
    6 1
    2

    输出#1

    0 2 6 8 4 1 3 5 7 9 
    -1

说明/提示

null

输入解题思路,AI测评打分。不知道怎么写?

首页