Contest Duration: - (local time) (100 minutes) Back to Home

Submission #6563739

Source Code Expand

Copy
```import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
final int MOD = (int)1e9+7;
void printlnYN(boolean b){out.println((b ? "YES" : "NO"));}

//System.out.println();はつかわない！！
void solve() throws Exception{
int N = in.nextInt();
int[] p = in.nextIntArray(N);
int cnt = 0;
for(int i = 0; i < N; i++){
if(p[i] != (i+1)) cnt++;
}

if(cnt == 0 || cnt == 2){
printlnYN(true);
}else printlnYN(false);
}

public static void main(String[] args) throws Exception {
new Main().m();
}

void m() throws Exception {
solve();
out.flush();
}

class FastScanner {

FastScanner() {this(System.in);}

int nextInt() {return (int) nextLong();}

long nextLong() {
try {
int sign = 1;
while ((b < '0' || '9' < b) && b != '-' && b != '+') {
}
if (b == '-') {
sign = -1;
} else if (b == '+') {
}
long ret = b - '0';
while (true) {
if (b < '0' || '9' < b) return ret * sign;
ret *= 10;
ret += b - '0';
}
} catch (IOException e) {
e.printStackTrace();
return -1;
}
}

double nextDouble() {
try {
double sign = 1;
while ((b < '0' || '9' < b) && b != '-' && b != '+') {
}
if (b == '-') {
sign = -1;
} else if (b == '+') {
}
double ret = b - '0';
while (true) {
if (b < '0' || '9' < b) break;
ret *= 10;
ret += b - '0';
}
if (b != '.') return sign * ret;
double div = 1;
while ('0' <= b && b <= '9') {
ret *= 10;
ret += b - '0';
div *= 10;
}
return sign * ret / div;
} catch (IOException e) {
e.printStackTrace();
return Double.NaN;
}
}

char nextChar() {
try {
while (Character.isWhitespace(b)) {
}
return (char) b;
} catch (IOException e) {
e.printStackTrace();
return 0;
}
}

String nextStr() {
try {
StringBuilder sb = new StringBuilder();
while (Character.isWhitespace(b)) {
}
while (b != -1 && !Character.isWhitespace(b)) {
sb.append((char) b);
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
return "";
}
}

public int[] nextIntArray(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt();
}
return res;
}

public int[] nextIntArrayDec(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt() - 1;
}
return res;
}

public int[] nextIntArray1Index(int n) {
int[] res = new int[n + 1];
for (int i = 0; i < n; i++) {
res[i + 1] = nextInt();
}
return res;
}

public long[] nextLongArray(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nextLong();
}
return res;
}

public long[] nextLongArrayDec(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nextLong() - 1;
}
return res;
}

public long[] nextLongArray1Index(int n) {
long[] res = new long[n + 1];
for (int i = 0; i < n; i++) {
res[i + 1] = nextLong();
}
return res;
}

public double[] nextDoubleArray(int n) {
double[] res = new double[n];
for (int i = 0; i < n; i++) {
res[i] = nextDouble();
}
return res;
}
}
}
/* end Main */```

#### Submission Info

Submission Time 2019-07-27 21:05:59+0900 B - 0 or 1 Swap Oland Java8 (OpenJDK 1.8.0) 200 4235 Byte AC 71 ms 21204 KB

#### Judge Result

Set Name All Sample
Score / Max Score 200 / 200 0 / 0
Status
 AC × 16
 AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_0, testcase_1, testcase_10, testcase_11, testcase_2, testcase_3, testcase_4, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9, testcase_add1
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 71 ms 19540 KB
sample_02 AC 68 ms 17876 KB
sample_03 AC 68 ms 16340 KB
testcase_0 AC 69 ms 19284 KB
testcase_1 AC 70 ms 16980 KB
testcase_10 AC 69 ms 19796 KB
testcase_11 AC 69 ms 21204 KB
testcase_2 AC 68 ms 17748 KB
testcase_3 AC 69 ms 21204 KB
testcase_4 AC 70 ms 19028 KB
testcase_5 AC 69 ms 19412 KB
testcase_6 AC 68 ms 18644 KB
testcase_7 AC 68 ms 20052 KB
testcase_8 AC 69 ms 21076 KB
testcase_9 AC 70 ms 20948 KB
testcase_add1 AC 69 ms 18644 KB