No.3007 Braid
タグ : / 解いたユーザー数 14
作問者 :
ジュ・ビオレ・グレイス
/ テスター :
👑 Problem Statement
Consider the following operations on finite sequences (the empty sequence is also allowed) consisting of integers between $1$ and $N$, inclusive:
- Remove two consecutive occurrences of the same number between $1$ and $N$, inclusive.
- Insert two consecutive occurrences of the same number between $1$ and $N$, inclusive, at any position (the beginning and the end are also allowed).
- For integers between $1$ and $N$, inclusive, $i$ and $j$ such that $|i-j| > 1$, rewrite adjacent $i, \ j$ as $j, \ i$.
- For an integer at least $1$ and $N$ less than, namely $i$, rewrite adjacent $i,\ i+1, \ i$ as $i+1, \ i, \ i+1$.
- For an integer at least $1$ and $N$ less than, namely $i$, rewrite adjacent $i+1, \ i, \ i+1$ as $i,\ i+1, \ i$.
Now, given sequences $A_1, \dots, A_K$ and $B_1, \dots, B_L$ from the input, consisting of integers between $1$ and $N$, inclusive, determine whether they are connectable, and print
YES if they are connectable and NO otherwise.
Input
$N \ K \ L$ $A_1 \ \cdots \ A_K$ $B_1 \ \cdots \ B_L$
$1 \leq N, K, L \leq 10^4,$
$1 \leq A_k, B_l \leq N.$
Output
Print a newline at the end.
Sample
Sample 1
Input
1 3 2 1 1 1 1 1
Output
NO
When $N = 1$, the problem reduces to determining the parity of $K - L$.
Sample 2
Input
4 4 6 3 2 4 3 2 3 4 2 3 4
Output
YES
$3 \ 2 \ 4 \ 3 \rightarrow 3 \ 2 \ 3 \ 3 \ 4 \ 3 \rightarrow 2 \ 3 \ 2 \ 3 \ 4 \ 3 \rightarrow 2 \ 3 \ 2 \ 4 \ 3 \ 4 \rightarrow 2 \ 3 \ 4 \ 2 \ 3 \ 4$
Sample 3
Input
100 7 8 3 8 13 18 23 28 33 4 8 12 16 20 24 28 32
Output
NO
The operations given in the problem statement do not change the parity of the length of the sequence, so these sequences cannot be transformed into each other.
Sample 4
Input
100 2 6 1 1 99 100 99 100 99 100
Output
YES
$99 \ 100 \ 99 \ 100 \ 99 \ 100 \leftarrow 100 \ 99 \ 100 \ 100 \ 99 \ 100 \leftarrow 100 \ 99 \ 99 \ 100 \leftarrow 100 \ 100 \leftarrow \ \ \ \leftarrow 1 \ 1$
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。