목차

빵 정렬

ps
링크acmicpc.net/…
출처BOJ
문제 번호5000
문제명빵 정렬
레벨플래티넘 3
분류

불변성

시간복잡도O(n)
인풋사이즈n<=100000
사용한 언어Python 3.13
제출기록47088KB / 112ms
최고기록108ms
해결날짜2025/11/13

풀이

코드

"""Solution code for "BOJ 5000. 빵 정렬".

- Problem link: https://www.acmicpc.net/problem/5000
- Solution link: http://www.teferi.net/ps/problems/boj/5000
"""

from teflib import permcycle


def main():
    _n = int(input())
    cur_order = [int(x) - 1 for x in input().split()]
    target_order = [int(x) - 1 for x in input().split()]

    cur_parity = permcycle.sign_of_permutation(cur_order)
    target_parity = permcycle.sign_of_permutation(target_order)
    print('Possible' if cur_parity == target_parity else 'Impossible')


if __name__ == '__main__':
    main()