88732024-02-02 18:16:36NagyLeoLegmesszebbi rossz sorrendű (35 pont)python3Time limit exceeded 19/35300ms37304 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/017ms11120 KiB
2Time limit exceeded0/0300ms15740 KiB
3Accepted1/118ms12116 KiB
4Accepted1/117ms12072 KiB
5Accepted1/117ms11888 KiB
6Accepted1/117ms12420 KiB
7Accepted1/117ms12316 KiB
8Accepted1/120ms12704 KiB
9Accepted1/124ms13144 KiB
10Accepted1/128ms13456 KiB
11Accepted1/130ms13720 KiB
12Accepted2/2174ms21816 KiB
13Accepted2/2195ms23224 KiB
14Time limit exceeded0/2208ms24284 KiB
15Accepted2/2133ms19396 KiB
16Time limit exceeded0/2217ms25112 KiB
17Time limit exceeded0/2280ms13784 KiB
18Time limit exceeded0/2280ms15320 KiB
19Time limit exceeded0/2280ms15660 KiB
20Time limit exceeded0/2280ms16512 KiB
21Time limit exceeded0/2287ms17660 KiB
22Time limit exceeded0/2273ms18096 KiB
23Accepted2/294ms37272 KiB
24Accepted2/296ms37304 KiB