88772024-02-02 18:29:05NagyLeoLegmesszebbi rossz sorrendű (35 pont)python3Wrong answer 6/35141ms37128 KiB
def find_misplaced_elements(nums, n):
    max_length = 0
    first_num = 0
    second_num = 0
    minimums = [0] * n
    # minimums[-i] megmondja a leghatso i minimumat
    minimums[-1] = nums[-1]
    for i in range(n - 2, -1, -1):
        minimums[i] = min(minimums[i + 1], nums[i])
    for i in range(n - 1):
        # if minimums[i+1] >= nums[i]:
        #    continue
        if minimums[-1] < nums[i]:
            if n - 1 - i > max_length:
                max_length = n - 1 - i
                first_num = i
                second_num = n - 1
                continue
        lo = min(max_length + i + 1, n - 1)
        hi = n - 1
        if minimums[lo] >= nums[i]:
            continue
        while hi - lo > 1:
            mid = (lo + hi) // 2
            if minimums[mid] < nums[i]:
                lo = mid
            else:
                hi = mid
        max_length = lo - i
        first_num = i
        second_num = lo

    if max_length > 0:
        print(first_num + 1, second_num + 1)
    else:
        print(-1)


n = int(input())
nums = list(map(int, input().split()))

find_misplaced_elements(nums, n)
SubtaskSumTestVerdictTimeMemory
base6/35
1Accepted0/018ms11288 KiB
2Wrong answer0/0141ms34848 KiB
3Accepted1/117ms11620 KiB
4Accepted1/117ms11792 KiB
5Accepted1/117ms12080 KiB
6Accepted1/118ms12280 KiB
7Wrong answer0/118ms12368 KiB
8Wrong answer0/118ms12892 KiB
9Wrong answer0/120ms13144 KiB
10Wrong answer0/120ms13472 KiB
11Wrong answer0/121ms14128 KiB
12Wrong answer0/264ms22176 KiB
13Wrong answer0/270ms23596 KiB
14Accepted2/274ms24464 KiB
15Wrong answer0/252ms19800 KiB
16Wrong answer0/275ms25468 KiB
17Wrong answer0/2101ms29052 KiB
18Wrong answer0/2112ms32324 KiB
19Wrong answer0/2123ms32996 KiB
20Wrong answer0/2126ms34704 KiB
21Wrong answer0/2141ms36620 KiB
22Wrong answer0/2138ms37128 KiB
23Wrong answer0/2134ms37096 KiB
24Wrong answer0/2135ms36892 KiB