CF1842H.Tenzing and Random Real Numbers

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are nn uniform random real variables between 0 and 1, inclusive, which are denoted as x1,x2,…,xnx_1, x_2, \ldots, x_n.

Tenzing has mm conditions. Each condition has the form of xi+xj≤1x_i+x_j\le 1 or xi+xj≥1x_i+x_j\ge 1.

Tenzing wants to know the probability that all the conditions are satisfied, modulo 998 244 353998~244~353.

Formally, let M=998 244 353M = 998~244~353. It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, output the integer xx that 0≤x<M0 \le x \lt M and x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}.

有 nn 个在区间 [0,1][0,1] 上独立均匀分布的实随机变量,记为 x1,x2,…,xnx_1, x_2, \ldots, x_n。

丹增提出了 mm 个约束条件。每个约束形如 xi+xj≤1x_i + x_j \le 1 或 xi+xj≥1x_i + x_j \ge 1。

丹增希望知道所有约束同时被满足的概率,结果对 998 244 353998~244~353 取模。

形式化地,令 M=998 244 353M = 998~244~353。可以证明该概率可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,输出满足 0≤x<M0 \le x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入格式

The first line contains two integers nn and mm (1≤n≤201\le n\le 20, 0≤m≤n2+n0\le m\le n^2+n).

Then following mm lines of input contains three integers tt, ii and jj (t∈0,1t \in {0,1}, 1≤i≤j≤n1\le i\le j\le n).

  • If t=0t=0, the condition is xi+xj≤1x_i+x_j\le 1.
  • If t=1t=1, the condition is xi+xj≥1x_i+x_j\ge 1.

It is guaranteed that all conditions are pairwise distinct.

第一行包含两个整数 nn 和 mm(1≤n≤201\le n\le 20,0≤m≤n2+n0\le m\le n^2+n)。

接下来的 mm 行每行包含三个整数 tt、ii 和 jj(t∈{0,1}t \in \{0,1\},1≤i≤j≤n1\le i\le j\le n)。

  • 若 t=0t=0,则约束条件为 xi+xj≤1x_i+x_j\le 1;
  • 若 t=1t=1,则约束条件为 xi+xj≥1x_i+x_j\ge 1。

保证所有约束条件两两互不相同。

输出格式

Output the probability that all the conditions are satisfied, modulo M=998 244 353M = 998~244~353.

输出所有条件均被满足的概率,对 M=998 244 353M = 998~244~353 取模。

输入输出样例

  • 输入#1

    3 2
    0 1 2
    1 3 3

    输出#1

    748683265
  • 输入#2

    3 3
    0 1 2
    0 1 3
    0 2 3

    输出#2

    748683265
  • 输入#3

    3 4
    0 1 2
    0 1 3
    1 2 3
    1 2 2

    输出#3

    935854081
  • 输入#4

    4 4
    0 1 2
    0 3 4
    1 1 3
    1 2 4

    输出#4

    0
  • 输入#5

    8 12
    0 1 2
    0 2 3
    1 3 4
    0 1 4
    0 5 6
    0 6 7
    1 7 8
    0 5 8
    1 3 7
    1 3 8
    1 4 7
    1 4 8

    输出#5

    997687297

说明/提示

In the first test case, the conditions are x1+x2≤1x_1+x_2 \le 1 and x3+x3≥1x_3+x_3\ge 1, and the probability that each condition is satisfied is 12\frac 12, so the probability that they are both satisfied is 12⋅12=14\frac 12\cdot \frac 12=\frac 14, modulo 998 244 353998~244~353 is equal to 748683265748683265.

In the second test case, the answer is 14\frac 14.

In the third test case, the answer is 116\frac 1{16}.

In the fourth test case, the sum of all variables must equal 22, so the probability is 00.

在第一个测试用例中,约束条件为 x1+x2≤1x_1+x_2 \le 1 和 x3+x3≥1x_3+x_3\ge 1,每个约束条件被满足的概率均为 12\frac 12,因此两个约束条件同时被满足的概率为 12⋅12=14\frac 12\cdot \frac 12=\frac 14,对 998 244 353998~244~353 取模的结果为 748683265748683265。

在第二个测试用例中,答案为 14\frac 14。

在第三个测试用例中,答案为 116\frac 1{16}。

在第四个测试用例中,所有变量之和必须等于 22,因此概率为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页