88692024-02-02 17:35:27NagyLeoLegmesszebbi rossz sorrendű (35 pont)python3Wrong answer 1/3561ms37440 KiB
def binary_search(nums, target, left, right):
    while left <= right:
        mid = (left + right) // 2
        if nums[mid] == target:
            return mid
        elif nums[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

def find_misplaced_elements(nums):
    n = len(nums)
    max_index = 0
    min_index = n - 1

    for i in range(1, n):
        if nums[i] < nums[i - 1]:
            max_index = i - 1
            break

    for i in range(n - 2, -1, -1):
        if nums[i] > nums[i + 1]:
            min_index = i + 1
            break

    if max_index == 0 and min_index == n - 1:
        return -1

    correct_max_index = binary_search(nums, nums[max_index], min_index, n - 1)

    correct_min_index = binary_search(nums, nums[min_index], 0, max_index)

    return max_index, correct_min_index if correct_min_index != -1 else min_index

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

# Find the indices of the misplaced elements
result = find_misplaced_elements(nums)

# Print the result
if result == -1:
    print(-1)
else:
    print(result[0], result[1])
SubtaskSumTestVerdictTimeMemory
base1/35
1Wrong answer0/017ms11456 KiB
2Wrong answer0/050ms34532 KiB
3Accepted1/118ms11736 KiB
4Wrong answer0/117ms12008 KiB
5Wrong answer0/117ms12128 KiB
6Wrong answer0/117ms11928 KiB
7Wrong answer0/117ms12448 KiB
8Wrong answer0/117ms12704 KiB
9Wrong answer0/117ms13316 KiB
10Wrong answer0/118ms13380 KiB
11Wrong answer0/118ms13800 KiB
12Wrong answer0/228ms21588 KiB
13Wrong answer0/232ms23460 KiB
14Wrong answer0/232ms24108 KiB
15Wrong answer0/228ms19556 KiB
16Wrong answer0/234ms24872 KiB
17Wrong answer0/239ms28732 KiB
18Wrong answer0/241ms30952 KiB
19Wrong answer0/246ms33172 KiB
20Wrong answer0/245ms35080 KiB
21Wrong answer0/250ms36888 KiB
22Wrong answer0/248ms37440 KiB
23Wrong answer0/259ms37244 KiB
24Wrong answer0/261ms37000 KiB