AT_arc228_a.Row and Col swap
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given permutations P=(P1,P2,…,PN) and Q=(Q1,Q2,…,QN) of (1,2,…,N).
For P and Q, you repeat the following M times: choose and perform one of the operations below.
- Choose integers i and j satisfying 1≤i<j≤N, and swap Pi and Pj.
- Choose integers i and j satisfying 1≤i<j≤N, and swap Qi and Qj.
- Choose an integer i satisfying 1≤i≤N, and swap Pi and Qi.
Find the number, modulo 998244353, of sequences of operations such that both P and Q are permutations of (1,2,…,N) after the M operations.
给你两个 (1,2,…,N) 的排列 P=(P1,P2,…,PN) 和 Q=(Q1,Q2,…,QN)。
对 P 和 Q,重复执行以下操作共 M 次:
- 选择满足 1≤i<j≤N 的整数 i 和 j,交换 Pi 与 Pj;
- 选择满足 1≤i<j≤N 的整数 i 和 j,交换 Qi 与 Qj;
- 选择满足 1≤i≤N 的整数 i,交换 Pi 与 Qi。
求满足“经过 M 次操作后,P 和 Q 均仍为 (1,2,…,N) 的排列”的操作序列的个数,答案对 998244353 取模。
输入格式
The input is given from Standard Input in the following format:
N M
P1 P2 … PN
Q1 Q2 … QN
输入从标准输入中按以下格式给出:
N M
P1 P2 … PN
Q1 Q2 … QN
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
3 1 1 2 3 1 3 2
输出#1
7
输入#2
3 2 1 2 3 1 3 2
输出#2
53
输入#3
8 15 6 4 8 3 2 7 1 5 1 6 4 5 7 2 8 3
输出#3
571380540
说明/提示
Sample 1 Explanation:
For example, the following sequence of operations satisfies the condition.
- Choose i=1 in an operation of the third kind to swap P1 and Q1. Now P=(1,2,3) and Q=(1,3,2).
Any sequence of operations composed of exactly one of the following seven operations satisfies the condition: the three operations that swap two elements of P, the three operations that swap two elements of Q, and the operation described above that swaps P1 and Q1.
Constraints
- 1≤N,M≤500
- P and Q are permutations of (1,2,…,N).
- All input values are integers.
样例 1 解释:
例如,以下操作序列满足条件。
- 在第三类操作中选择 i=1,交换 P1 和 Q1。此时 P=(1,2,3),Q=(1,3,2)。
任何恰好由以下七种操作之一构成的操作序列均满足条件:三类交换 P 中两个元素的操作、三类交换 Q 中两个元素的操作,以及上述交换 P1 和 Q1 的操作。
限制条件
- 1≤N,M≤500
- P 和 Q 均为 (1,2,…,N) 的排列。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?