No.1530 Permutation and Popcount
タグ : / 解いたユーザー数 28
作問者 :
PCTprobability
/ テスター :
tatyam
penguinman
Problem Statement
Let $\mathrm{popcount}(n)$ be the number of $1$s in the $2$-ary representation of $n$. For example, $\mathrm{popcount}(11)=3,\ \mathrm{popcount}(64)=1$.
For a sequence of positive integers $A_1,A_2,\dots,A_K$, define $f(A)$ as follows.
- The number of pairs of positive integers $(i,j)$ such that $1 \le i,j \le K$ and $\mathrm{popcount}(A_i \times A_j) \equiv 0 \pmod 2$
Construct a pair of sequences of positive integers $(X_1,X_2,\dots,X_P),(Y_1,Y_2,\dots,Y_Q)$ satisfying the following. If no such pair exists, report that.
- $X,Y$ is a pair of sequences obtained by splitting $(1,2,3,\dots,N)$ into $2$ sequences. Formally, the following hold.
- $0 \le P,Q$
- $P+Q=N$
- $1 \le X_i \le N$
- $1 \le Y_j \le N$
- If $i \neq j$, then $X_i \neq X_j$
- If $i \neq j$, then $Y_i \neq Y_j$
- $X_i \neq Y_j$
- $f(X)-f(Y)=M$
Input
$N\ M$
- All inputs are integers.
- $2 \le N \le 300$
- $0 \le M \le N^2$
Output
If no pair of sequences of positive integers $(X_1,X_2,\dots,X_P),(Y_1,Y_2,\dots,Y_Q)$ satisfying the conditions exists, print $-1$.
If a pair of sequences of positive integers $(X_1,X_2,\dots,X_P),(Y_1,Y_2,\dots,Y_Q)$ satisfying the conditions exists, print $1$ solution in the following format.
If there are multiple solutions, you may print any of them.
$P\ Q$
$X_1\ X_2\ \dots\ X_P$
$Y_1\ Y_2\ \dots\ Y_Q$
Sample
Sample 1
Input
5 1
Output
3 2
1 2 5
3 4
Since $f(1,2,5)=4,f(3,4)=3$, the condition $f(X)-f(Y)=1$ is satisfied. All other conditions are also satisfied, so this output is correct.
Sample 2
Input
6 7
Output
-1
No pair of sequences satisfying the conditions exists. Therefore, print $-1$.
Sample 3
Input
19 43
Output
11 8 13 12 10 18 14 6 5 8 3 16 4 19 9 17 1 15 7 11 2
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。