

Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
(1,2,3,4,5) を並び替えた整数列 A=(A_1,A_2,A_3,A_4,A_5) が与えられます。
A の隣り合う 2 つの項を入れ替える操作を ちょうど 1 回 行うことで A を昇順にすることができるか判定してください。
制約
- A は (1,2,3,4,5) を並び替えてできる長さ 5 の整数列
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 A_3 A_4 A_5
出力
ちょうど 1 回の操作で A を昇順にすることができるならば Yes
を、できないならば No
を出力せよ。
入力例 1
1 2 4 3 5
出力例 1
Yes
A_3 と A_4 を入れ替えることで A=(1,2,3,4,5) となり、 A を昇順に並び替えることができます。したがって、 Yes
を出力してください。
入力例 2
5 3 2 4 1
出力例 2
No
どのような操作をしても A を昇順に並び替えることはできません。
入力例 3
1 2 3 4 5
出力例 3
No
ちょうど 1 回操作をする必要があります。
入力例 4
2 1 3 4 5
出力例 4
Yes
Score : 150 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,A_3,A_4,A_5) obtained by permuting (1,2,3,4,5).
Determine whether A can be sorted in ascending order by performing exactly one operation of swapping two adjacent elements in A.
Constraints
- A is an integer sequence of length 5 obtained by permuting (1,2,3,4,5).
Input
The input is given from Standard Input in the following format:
A_1 A_2 A_3 A_4 A_5
Output
If A can be sorted in ascending order by exactly one operation, print Yes
; otherwise, print No
.
Sample Input 1
1 2 4 3 5
Sample Output 1
Yes
By swapping A_3 and A_4, A becomes (1,2,3,4,5), so it can be sorted in ascending order. Therefore, print Yes
.
Sample Input 2
5 3 2 4 1
Sample Output 2
No
No matter what operation is performed, it is impossible to sort A in ascending order.
Sample Input 3
1 2 3 4 5
Sample Output 3
No
You must perform exactly one operation.
Sample Input 4
2 1 3 4 5
Sample Output 4
Yes