303702: CF715E. Complete the Permutations
Memory Limit:256 MB
Time Limit:5 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Complete the Permutations
题意翻译
给定两个排列 $p,q$,但是其中有些位置未知,用 $0$ 表示。 现在让你补全两个排列,定义两个排列 $p,q$ 之间的距离为每次选择 $p$ 中两个元素交换,使其变成 $q$ 的最小次数。 现在你需求出对于 $i \in [0,n-1]$ 求出补全后相似度为 $i$ 的方案数。 $n \leq 250$。题目描述
ZS the Coder is given two permutations $ p $ and $ q $ of $ {1,2,...,n} $ , but some of their elements are replaced with $ 0 $ . The distance between two permutations $ p $ and $ q $ is defined as the minimum number of moves required to turn $ p $ into $ q $ . A move consists of swapping exactly $ 2 $ elements of $ p $ . ZS the Coder wants to determine the number of ways to replace the zeros with positive integers from the set $ {1,2,...,n} $ such that $ p $ and $ q $ are permutations of $ {1,2,...,n} $ and the distance between $ p $ and $ q $ is exactly $ k $ . ZS the Coder wants to find the answer for all $ 0<=k<=n-1 $ . Can you help him?输入输出格式
输入格式
The first line of the input contains a single integer $ n $ ( $ 1<=n<=250 $ ) — the number of elements in the permutations. The second line contains $ n $ integers, $ p_{1},p_{2},...,p_{n} $ ( $ 0<=p_{i}<=n $ ) — the permutation $ p $ . It is guaranteed that there is at least one way to replace zeros such that $ p $ is a permutation of $ {1,2,...,n} $ . The third line contains $ n $ integers, $ q_{1},q_{2},...,q_{n} $ ( $ 0<=q_{i}<=n $ ) — the permutation $ q $ . It is guaranteed that there is at least one way to replace zeros such that $ q $ is a permutation of $ {1,2,...,n} $ .
输出格式
Print $ n $ integers, $ i $ -th of them should denote the answer for $ k=i-1 $ . Since the answer may be quite large, and ZS the Coder loves weird primes, print them modulo $ 998244353=2^{23}·7·17+1 $ , which is a prime.
输入输出样例
输入样例 #1
3
1 0 0
0 2 0
输出样例 #1
1 2 1
输入样例 #2
4
1 0 0 3
0 0 0 4
输出样例 #2
0 2 6 4
输入样例 #3
6
1 3 2 5 4 6
6 4 5 1 0 0
输出样例 #3
0 0 0 0 1 1
输入样例 #4
4
1 2 3 4
2 3 4 1
输出样例 #4
0 0 0 1