포럼
문제 ICPC00320

D. Deck Randomisation

설명

Alice and Bob love playing Don'tminion, which typically involves a lot of shuffling of decks of different sizes. Because they play so often, they are not only very quick at shuffling, but also very consistent. Each time Alice shuffles her deck, her cards get permuted in the same way, just like Bob always permutes his cards the same way when he shuffles them. This isn't good for playing games, but raises an interesting question.

They know that if they take turns shuffling, then at some point the deck will end up ordered in the same way as when they started. Alice shuffles once first, then Bob shuffles once, then Alice shuffles again, et cetera. They start with a sorted deck. What they do not know, however, is how many shuffles it will take before the deck is sorted again.

Can you help them compute how many shuffles it will take? As Alice and Bob can only do \(10^{12}\) shuffles in the limited time they have, any number strictly larger than this should be returned as huge instead.

제약
입력 형식
  • The first line contains a single integer \(1\leq n\leq 10^5\), the number of cards in the deck.
  • The second line contains \(n\) distinct integers $1\leq a_1, a_2,
    \dotsc, a_n \leq n\(, where \)a_i\( is\ the\ new\ position\ of\ the\ card\ previously\ at\ position \)i$ when Alice shuffles the deck.
  • The third line contains \(n\) distinct integers $1\leq
    b_1,b_2,\dotsc, b_n\leq n\(, where \)b_i\( is\ the\ new\ position\ of\ the\ card\ previously\ at\ position \)i$ when Bob shuffles the deck.
출력 형식
  • Output a single positive integer \(m > 0\), the minimal number of shuffles required to sort the deck, or huge when this number is strictly larger than \(10^{12}\).
예제 1
입력
3
2 3 1
3 1 2
출력
2
예제 2
입력
6
5 1 6 3 2 4
4 6 5 1 3 2
출력
5
예제 3
입력
8
1 4 2 6 7 8 5 3
3 6 8 4 7 1 5 2
출력
10
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2019

평가 및 의견

D. Deck Randomisation

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

D. Deck Randomisation

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8