問題一覧 > 通常問題

No.1635 Let’s Sort Integers!!

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 17
作問者 : とりゐ / テスター : logx re_re0101 👑 qand
お気に入りにしたユーザー ProblemId : 6623 / 自分の提出
問題文最終更新日: 2021-08-13 14:16:03
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 307 (順位表) の他の問題:

Problem Statement

You are given positive integers $N,K$. Determine whether there exists a permutation $P$ obtained by rearranging $1,2,\ldots, N$ that satisfies the following condition, and if one exists, construct one such example.

  • $|P_1-P_2|+|P_2-P_3|+\cdots+|P_{N-1}-P_N|=K$

Input

$N\ K$

  • $2\leq N\leq 10^6$
  • $1\leq K\leq10^{18}$
  • All inputs are integers.

Output

If no permutation $P$ satisfying the condition exists, output -1.

If a permutation $P$ satisfying the condition exists, output $1$ such permutation in the following format.

$P_1\ P_2\ \ldots\ P_N$

Sample

Sample 1
Input
4 5
Output
2 1 4 3

This satisfies the condition since $|2-1|+|1-4|+|4-3|=5$. Other outputs such as 1 4 3 2 and 4 2 3 1 also satisfy the condition.

Sample 2
Input
2 1
Output
1 2

This satisfies the condition since $|1-2|=1$. 2 1 also satisfies the condition.

Sample 3
Input
3 1
Output
-1

No permutation $P$ satisfying the condition exists.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。