No.1509 Swap!!
問題文最終更新日: 2021-05-13 23:13:30
English (AI translation)
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 295
(順位表)
の他の問題:
Problem Statement
You can perform the following $2$ operations, in any order and any number of times, on a permutation $P=(P_1,P_2,\ldots,P_N)$ of length $N$ obtained by rearranging the positive integers from $1$ to $N$ inclusive.
・Choose an integer $i$ satisfying $1\le i \le N-A$, and swap the values of $P_i$ and $P_{i+A}$. ・Choose an integer $i$ satisfying $1\le i \le N-B$, and swap the values of $P_i$ and $P_{i+B}$. Your final goal is to sort $P$ in ascending order. Determine whether the goal can be achieved regardless of the initial state of $P$. You are given $T$ test cases; find the answer for each of them.Constraints
Input
$T$ $case_1$ $\vdots$ $case_T$Each test case is given in the following format.
$N$ $A$ $B$
Output
Print $T$ lines.
On the $i$-th line, printYES if the goal can be achieved for the $i$-th test case, and NO otherwise.
Sample
Sample 1
Input
3 3 1 2 4 2 2 10000000000000000 1122334455667788 9988776655443322
Output
YES NO NOConsider the $1$st test case. For example, if the initial state is $3\ 1\ 2$, then $3\ 2\ 1$ (swap the $2$nd and $3$rd elements) $1\ 2\ 3$ (swap the $1$st and $3$rd elements) sorts it in ascending order. The other permutations of length $3$ can also be sorted in ascending order by appropriate swaps, so print
YES.
In the $2$nd test case, for example, if the initial state is $4\ 3\ 2\ 1$, it cannot be sorted in ascending order no matter how you rearrange it.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
mine691