#P14369. [ICPC 2024 NAC] House Deconstruction

    ID: 13586 传统题 1000ms 256MiB 尝试: 1 已通过: 1 难度: 7 上传者: 标签>CF2300贪心图论动态规划模拟前缀和组合数学

[ICPC 2024 NAC] House Deconstruction

Problem Description

In Circleland, there is a circle with x equally spaced points on its circumference.
Adjacent points are at distance 1 along the circle.

Some points contain people, some contain houses, and some contain nothing.
Each person wants to walk to a different house, and each house can hold at most one person.
People may only walk along the circumference of the circle.

There are more houses than people, so you will destroy some houses.
If you destroy a set of houses S, let f(S) be the minimum total walking distance needed to send every person to a different house that is not destroyed.

Your task is:

  1. compute the minimum possible value of f(S),
  2. count how many sets S achieve that minimum.

Because the number of valid sets can be large, output it modulo 998244353.

Input

The first line contains three integers x, n, and m:

  • 1 <= n < m <= 2 * 10^5
  • n + m <= x <= 10^9

where:

  • x is the number of points on the circle,
  • n is the number of people,
  • m is the number of houses.

Points are labeled from 1 to x, and point x is adjacent to point 1.

The next n + m lines each contain:

p t

where:

  • 1 <= p <= x
  • t is either P or H

p is the position of the point, and t indicates whether that point contains a person (P) or a house (H).

All positions are distinct and are given in increasing order.

Output

Output two lines:

  1. the minimum possible value of f(S),
  2. the number of sets S that achieve this minimum, modulo 998244353.

Sample Explanation

For the first sample, the minimum total walking distance is 2.
Possible destroyed-house sets are {2, 5}, {4, 5}, and {5, 6}.

For the second sample, the minimum total walking distance is 4.
Destroying {6, 31415926} achieves this value.
Even if the minimum matching can be realized in multiple ways, it is counted only once because the destroyed-house set is the same.

Sample Input 1

6 2 4
1 P
2 H
3 P
4 H
5 H
6 H

Sample Output 1

2
3

Sample Input 2

1000000000 2 4
1 P
6 H
31415926 H
999999998 H
999999999 H
1000000000 P

Sample Output 2

4
1