CF715E.Complete the Permutations

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

ZS the Coder is given two permutations pp and qq of 1,2,...,n{1,2,...,n} , but some of their elements are replaced with 00 . The distance between two permutations pp and qq is defined as the minimum number of moves required to turn pp into qq . A move consists of swapping exactly 22 elements of pp .

ZS the Coder wants to determine the number of ways to replace the zeros with positive integers from the set 1,2,...,n{1,2,...,n} such that pp and qq are permutations of 1,2,...,n{1,2,...,n} and the distance between pp and qq is exactly kk .

ZS the Coder wants to find the answer for all 0<=k<=n10<=k<=n-1 . Can you help him?

输入格式

The first line of the input contains a single integer nn ( 1<=n<=2501<=n<=250 ) — the number of elements in the permutations.

The second line contains nn integers, p1,p2,...,pnp_{1},p_{2},...,p_{n} ( 0<=pi<=n0<=p_{i}<=n ) — the permutation pp . It is guaranteed that there is at least one way to replace zeros such that pp is a permutation of 1,2,...,n{1,2,...,n} .

The third line contains nn integers, q1,q2,...,qnq_{1},q_{2},...,q_{n} ( 0<=qi<=n0<=q_{i}<=n ) — the permutation qq . It is guaranteed that there is at least one way to replace zeros such that qq is a permutation of 1,2,...,n{1,2,...,n} .

输出格式

Print nn integers, ii -th of them should denote the answer for k=i1k=i-1 . Since the answer may be quite large, and ZS the Coder loves weird primes, print them modulo 998244353=223717+1998244353=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 
    

说明/提示

In the first sample case, there is the only way to replace zeros so that it takes 00 swaps to convert pp into qq , namely p=(1,2,3),q=(1,2,3)p=(1,2,3),q=(1,2,3) .

There are two ways to replace zeros so that it takes 11 swap to turn pp into qq . One of these ways is p=(1,2,3),q=(3,2,1)p=(1,2,3),q=(3,2,1) , then swapping 11 and 33 from pp transform it into qq . The other way is p=(1,3,2),q=(1,2,3)p=(1,3,2),q=(1,2,3) . Swapping 22 and 33 works in this case.

Finally, there is one way to replace zeros so that it takes 22 swaps to turn pp into qq , namely p=(1,3,2),q=(3,2,1)p=(1,3,2),q=(3,2,1) . Then, we can transform pp into qq like following: .

首页