91152024-02-14 17:25:47NagyLeoKövetkező permutáció (50 pont)python3Time limit exceeded 4/50351ms12308 KiB
from itertools import permutations


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

    isAfter = False

    def test(numbers):
        for i in range(n - 2):
            for j in range(i + 1, n - 1):
                for k in range(j + 1, n):
                    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 A in permutations(range(1, n + 1)):
        if test(A) and isAfter:
            print(*A)
            break
        if A == numbers:
            isAfter = True


main()
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/017ms11424 KiB
2Time limit exceeded0/0252ms4940 KiB
3Accepted1/117ms11740 KiB
4Accepted1/129ms11916 KiB
5Accepted1/1159ms12308 KiB
6Accepted1/1131ms12152 KiB
7Time limit exceeded0/2349ms4792 KiB
8Time limit exceeded0/2268ms4956 KiB
9Time limit exceeded0/2268ms5436 KiB
10Time limit exceeded0/2275ms5540 KiB
11Time limit exceeded0/1270ms5632 KiB
12Time limit exceeded0/1256ms5724 KiB
13Time limit exceeded0/1287ms5752 KiB
14Time limit exceeded0/1275ms5672 KiB
15Time limit exceeded0/3280ms5940 KiB
16Time limit exceeded0/3351ms6144 KiB
17Time limit exceeded0/3263ms6348 KiB
18Time limit exceeded0/3284ms6544 KiB
19Time limit exceeded0/3347ms7224 KiB
20Time limit exceeded0/3268ms7644 KiB
21Time limit exceeded0/3300ms8012 KiB
22Time limit exceeded0/3272ms8388 KiB
23Time limit exceeded0/3340ms8504 KiB
24Time limit exceeded0/3351ms8560 KiB
25Time limit exceeded0/2275ms8716 KiB
26Time limit exceeded0/2272ms8656 KiB