91182024-02-14 17:55:37NagyLeoKövetkező permutáció (50 pont)pypy3Time limit exceeded 12/50354ms100856 KiB
from itertools import permutations


def main():
    n = int(input())
    numbers = list(map(int, input().split()))

    # isAfter = False

    def test(numbers):
        for i in range(len(numbers) - 2):
            for j in range(i + 1, len(numbers) - 1):
                for k in range(j + 1, len(numbers)):
                    if numbers[j] < numbers[k] and numbers[k] < numbers[i]:
                        return False
                        # if numbers[j] < numbers[k]:
                        #    numbers[j], numbers[k] = numbers[k], numbers[j]
        return True

    for i in range(n - 1, 0, -1):
        if numbers[i] > numbers[i - 1]:
            break

    for j in range(n - 1, -1, -1):
        if numbers[j] > numbers[i - 1]:
            break

    numbers[j], numbers[i - 1] = numbers[i - 1], numbers[j]

    # print(numbers,numbers[i:])

    for B in permutations(sorted(numbers[i:])):
        A = numbers[:i] + list(B)
        # print(A)
        if test(A):  # and isAfter:
            print(*A)
            break
        # if A == numbers:
        #    isAfter = True


main()
SubtaskSumTestVerdictTimeMemory
base12/50
1Accepted0/048ms76636 KiB
2Time limit exceeded0/0280ms24712 KiB
3Accepted1/150ms77376 KiB
4Accepted1/143ms77796 KiB
5Accepted1/141ms78416 KiB
6Accepted1/148ms78092 KiB
7Accepted2/248ms78424 KiB
8Accepted2/2151ms89012 KiB
9Accepted2/263ms88608 KiB
10Accepted2/246ms79020 KiB
11Time limit exceeded0/1352ms26868 KiB
12Time limit exceeded0/1284ms26804 KiB
13Time limit exceeded0/1284ms27032 KiB
14Time limit exceeded0/1282ms27024 KiB
15Time limit exceeded0/3279ms26680 KiB
16Time limit exceeded0/3282ms26736 KiB
17Time limit exceeded0/3282ms26456 KiB
18Time limit exceeded0/3282ms26784 KiB
19Time limit exceeded0/3342ms26952 KiB
20Time limit exceeded0/3354ms27340 KiB
21Time limit exceeded0/3282ms27788 KiB
22Time limit exceeded0/3263ms27600 KiB
23Time limit exceeded0/3277ms27768 KiB
24Time limit exceeded0/3266ms28024 KiB
25Runtime error0/286ms100856 KiB
26Time limit exceeded0/2273ms28128 KiB