Submission #7324733


Source Code Expand

import copy

N = int(input())
p = [int(i) for i in input().split(' ')]

has_changed = False
for i in range(N):
    expect = i + 1
    #print(p)
    #print(p[i], expect)
    if p[i] != expect:
        if has_changed:
            print('NO')
            exit()
        index = p[i] - 1
        if p[index] == expect:
            has_changed = True
            tmp = copy.deepcopy(p[i])
            p[i] = expect
            p[index] = tmp
            # print('change', p[i], p[index])
        else:
            print('NO')
            exit()

print('YES')

Submission Info

Submission Time
Task B - 0 or 1 Swap
User showwin
Language Python (3.4.3)
Score 200
Code Size 580 Byte
Status AC
Exec Time 23 ms
Memory 3444 KiB

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 22 ms 3444 KiB
sample_02 AC 23 ms 3444 KiB
sample_03 AC 22 ms 3444 KiB
testcase_0 AC 22 ms 3444 KiB
testcase_1 AC 22 ms 3444 KiB
testcase_10 AC 23 ms 3444 KiB
testcase_11 AC 22 ms 3444 KiB
testcase_2 AC 23 ms 3444 KiB
testcase_3 AC 22 ms 3444 KiB
testcase_4 AC 23 ms 3444 KiB
testcase_5 AC 22 ms 3444 KiB
testcase_6 AC 22 ms 3444 KiB
testcase_7 AC 22 ms 3444 KiB
testcase_8 AC 22 ms 3444 KiB
testcase_9 AC 22 ms 3444 KiB
testcase_add1 AC 23 ms 3444 KiB