CF932C.Permutation Cycle

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

For a permutation P[1... N] of integers from 1 to N, function f is defined as follows:

Let g(i) be the minimum positive integer j such that f(i, j) = i. We can show such j always exists.

For given N, A, B, find a permutation P of integers from 1 to N such that for 1 ≤ i ≤ N, g(i) equals either A or B.

对于一个由 11 到 NN 的整数构成的排列 P[1...N]P[1...N],函数 ff 定义如下:

令 g(i)g(i) 为满足 f(i, j)=if(i,\,j) = i 的最小正整数 jj。可以证明这样的 jj 恒存在。

给定 NN、AA、BB,请构造一个由 11 到 NN 的整数组成的排列 PP,使得对所有 1≤i≤N1 \le i \le N,均有 g(i)=Ag(i) = A 或 g(i)=Bg(i) = B。

输入格式

The only line contains three integers N, A, B (1 ≤ N ≤ 106, 1 ≤ A, B ≤ N).

唯一一行包含三个整数 NN、AA、BB(1 ≤ N ≤ 1061 ≤ N ≤ 10^6,1 ≤ A, B ≤ N1 ≤ A, B ≤ N)。

输出格式

If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to N.

如果不存在这样的排列,则输出 -1。否则,输出一个由 1 到 N 的整数构成的排列。

输入输出样例

  • 输入#1

    9 2 5

    输出#1

    6 5 8 3 4 1 9 2 7
  • 输入#2

    3 2 1

    输出#2

    1 2 3

说明/提示

In the first example, g(1) = g(6) = g(7) = g(9) = 2 and g(2) = g(3) = g(4) = g(5) = g(8) = 5

In the second example, g(1) = g(2) = g(3) = 1

在第一个例子中,g(1)=g(6)=g(7)=g(9)=2g(1) = g(6) = g(7) = g(9) = 2,且 g(2)=g(3)=g(4)=g(5)=g(8)=5g(2) = g(3) = g(4) = g(5) = g(8) = 5。

在第二个例子中,g(1)=g(2)=g(3)=1g(1) = g(2) = g(3) = 1。

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

首页