88752024-02-02 18:20:29NagyLeoLegmesszebbi rossz sorrendű (35 pont)python3Time limit exceeded 19/35287ms37452 KiB
def find_misplaced_elements(nums, n):
    max_length = -1
    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 = i + 1
        hi = n - 1
        while hi - lo > 1:
            mid = (lo + hi) // 2
            if minimums[mid] < nums[i]:
                lo = mid
            else:
                hi = mid
        if lo - i > max_length:
            max_length = lo - i
            first_num = i
            second_num = lo

    if max_length > -1:
        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
base19/35
1Accepted0/017ms11192 KiB
2Time limit exceeded0/0230ms15668 KiB
3Accepted1/117ms11788 KiB
4Accepted1/117ms12172 KiB
5Accepted1/117ms11712 KiB
6Accepted1/117ms12212 KiB
7Accepted1/117ms12608 KiB
8Accepted1/119ms13132 KiB
9Accepted1/123ms13240 KiB
10Accepted1/126ms13520 KiB
11Accepted1/129ms14128 KiB
12Accepted2/2172ms22312 KiB
13Accepted2/2196ms23616 KiB
14Time limit exceeded0/2208ms24372 KiB
15Accepted2/2133ms19852 KiB
16Time limit exceeded0/2215ms25200 KiB
17Time limit exceeded0/2252ms13856 KiB
18Time limit exceeded0/2272ms15552 KiB
19Time limit exceeded0/2259ms15764 KiB
20Time limit exceeded0/2287ms16612 KiB
21Time limit exceeded0/2272ms17444 KiB
22Time limit exceeded0/2259ms17916 KiB
23Accepted2/297ms36880 KiB
24Accepted2/297ms37452 KiB