#abc318h. Ex - Count Strong Test Cases
Ex - Count Strong Test Cases
Score : points
问题描述
Snuke 提出了以下问题。
给定两个排列 和 ,它们都是 的排列。现在我们按照以下方式构建一个包含 个顶点和 条边的图。
- 对于 按照顺序,在顶点 和 之间绘制一条权重为 的双向边。
从图中移除一些数量的边以消除循环,请找出移除边的最小可能总权重。
Alice 和 Bob 提出了以下解决方案。
Alice: 将答案初始化为 。对于 按照顺序,如果连接顶点 和 的边包含在一个循环中,则移除该边并将它的权重加到答案中。
Bob: 将答案初始化为 。对于 按照顺序,如果连接顶点 和 的边包含在一个循环中,则移除该边并将它的权重加到答案中。
Snuke 发现他们的解决方案都是不正确的,并想知道有多少输入情况下他们的解决方案都不能给出正确答案。
在所有可能的 种输入中,求出(模 )使得 Alice 和 Bob 的解决方案都无法给出正确答案的输入数量。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Snuke has come up with the following problem.
You are given permutations and of . Let us build a graph with vertices and edges as follows.
- For in this order, draw an edge of weight connecting vertices and bidirectionally.
When removing some number of edges to eliminate cycles from the graph, find the minimum possible total weight of the removed edges.
Alice and Bob came up with the following solutions.
Alice: Initialize the answer to . For in this order, if the edge connecting vertices and is contained in a cycle, remove that edge and add its weight to the answer.
Bob: Initialize the answer to . For in this order, if the edge connecting vertices and is contained in a cycle, remove that edge and add its weight to the answer.
Snuke has realized that their solutions are both incorrect, and he wants to know the number of inputs for which neither of their solutions gives the correct answer.
Among the possible inputs, find the number, modulo , of inputs for which neither Alice's nor Bob's solution gives the correct answer.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
3
Sample Output 1
4
The following four inputs satisfy the condition.
For example, for the input , the correct answer is , but Alice's solution gives and Bob's gives .
Sample Input 2
2
Sample Output 2
0
There may be no inputs that satisfy the condition.
Sample Input 3
6
Sample Output 3
314708
Sample Input 4
318
Sample Output 4
321484323
update @ 2024/3/10 09:06:05