Logo
(追記) (追記ここまで)

33067번 - Double Derangement 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB (추가 메모리 없음)3241679056.962%

문제

You are given two permutations $a$ and $b,ドル each of length $N$ containing every integer in the range $[1,N]$. Your task is to construct a new permutation $c$ of length $N$ that contains every integer in the range $[1,N],ドル such that for every index $i$ (1ドル$-indexed), the following condition is satisfied:

\[c_i \neq a_i \quad \text{and} \quad c_i \neq b_i.\]

In other words, for no index $i$ can $c_i$ be equal to $a_i$ or $b_i$​.

Given the permutations $a$ and $b,ドル determine how many such permutations $c$ exist.

입력

The first line of input contains a single integer $T,ドル denoting the number of test cases.

For each test case, the input is as follows:

  • The first line of each test case contains a single integer, $N,ドル denoting the length of the permutations. (1ドル \le N \le 16$)
  • The next line contains $N$ space-separated integers, denoting the permutation $a$. Here, the $i$-th integer denotes $a_i$​. (1ドル \le a_i \le N;$ $i \ne j \rightarrow a_i \ne a_j$​)
  • The next line contains $N$ space-separated integers, denoting the permutation $b$. Here, the $i$-th integer denotes $b_i$​. (1ドル \le b_i \le N;$ $i \ne j \rightarrow b_i \ne b_j$)

Sum of $N$ over all cases $\le 2,000円$.

출력

Output how many such permutations $c$ described in the problem exist.

제한

서브태스크 1 (40점)

Modified constraints apply: 1ドル \le N \le 8;$ Sum of $N$ over all cases $\le 1,000円$.

서브태스크 2 (40점)

Modified constraints apply: 1ドル \le N \le 16;$ $\boldsymbol{\underline{a=b}},$ i.e., the permutation $a$ and $b$ is same for all indices 1ドル \le i \le N;$ Sum of $N$ over all cases $\le 2,000円$.

서브태스크 3 (20점)

Original constraints apply: 1ドル \le N \le 16;$ Sum of $N$ over all cases $\le 2,000円$.

예제 입력 1

1
4
1 2 3 4
2 3 1 4

예제 출력 1

3

There are 3ドル$ such permutations:

\[[3,1,4,2] \qquad [3,4,2,1] \qquad [4,1,2,3]\]

노트

You may have to use a type larger than a 32ドル$-bit integer to prevent overflow in this problem.

출처

University > 서강대학교 > CSE4152 문제해결프로그래밍실습 > 2024-2학기 기말고사 코딩 테스트 3번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /