CF1795D.Triangle Coloring

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an undirected graph consisting of nn vertices and nn edges, where nn is divisible by 66. Each edge has a weight, which is a positive (greater than zero) integer.

The graph has the following structure: it is split into n3\frac{n}{3} triples of vertices, the first triple consisting of vertices 1,2,31, 2, 3, the second triple consisting of vertices 4,5,64, 5, 6, and so on. Every pair of vertices from the same triple is connected by an edge. There are no edges between vertices from different triples.

You have to paint the vertices of this graph into two colors, red and blue. Each vertex should have exactly one color, there should be exactly n2\frac{n}{2} red vertices and n2\frac{n}{2} blue vertices. The coloring is called valid if it meets these constraints.

The weight of the coloring is the sum of weights of edges connecting two vertices with different colors.

Let WW be the maximum possible weight of a valid coloring. Calculate the number of valid colorings with weight WW, and print it modulo 998244353998244353.

你被给定一个包含 nn 个顶点和 nn 条边的无向图,其中 nn 可被 66 整除。每条边都有一个权值,该权值为正整数(即大于零)。

该图具有如下结构:它被划分为 n3\frac{n}{3} 个三元组顶点,第一个三元组包含顶点 1,2,31, 2, 3,第二个三元组包含顶点 4,5,64, 5, 6,依此类推。同一三元组内的任意两个顶点之间均有一条边相连;不同三元组之间的顶点不存在边。

你需要将该图的所有顶点染成两种颜色:红色与蓝色。每个顶点必须恰好染一种颜色,且红色顶点与蓝色顶点的数量都必须恰好为 n2\frac{n}{2}。满足上述约束的染色方案称为合法染色。

染色方案的权值定义为:所有连接两个不同颜色顶点的边的权值之和。

令 WW 表示所有合法染色方案中可能达到的最大权值。请计算权值恰好为 WW 的合法染色方案总数,并将结果对 998244353998244353 取模后输出。

输入格式

The first line contains one integer nn (6≤n≤3⋅1056 \le n \le 3 \cdot 10^5, nn is divisible by 66).

The second line contains nn integers w1,w2,…,wnw_1, w_2, \dots, w_n (1≤wi≤10001 \le w_i \le 1000) — the weights of the edges. Edge 11 connects vertices 11 and 22, edge 22 connects vertices 11 and 33, edge 33 connects vertices 22 and 33, edge 44 connects vertices 44 and 55, edge 55 connects vertices 44 and 66, edge 66 connects vertices 55 and 66, and so on.

第一行包含一个整数 nn(6≤n≤3⋅1056 \le n \le 3 \cdot 10^5,且 nn 能被 66 整除)。

第二行包含 nn 个整数 w1,w2,…,wnw_1, w_2, \dots, w_n(1≤wi≤10001 \le w_i \le 1000),表示各条边的权重。其中,第 11 条边连接顶点 11 和 22,第 22 条边连接顶点 11 和 33,第 33 条边连接顶点 22 和 33,第 44 条边连接顶点 44 和 55,第 55 条边连接顶点 44 和 66,第 66 条边连接顶点 55 和 66,依此类推。

输出格式

Print one integer — the number of valid colorings with maximum possible weight, taken modulo 998244353998244353.

输出一个整数——具有最大可能权重的有效染色方案的数量,对 998244353998244353 取模。

输入输出样例

  • 输入#1

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

    输出#1

    36
  • 输入#2

    6
    4 2 6 6 6 4

    输出#2

    2

说明/提示

The following picture describes the graph from the first example test.

The maximum possible weight of a valid coloring of this graph is 3131.

下图描述了第一个示例测试用例中的图。

该图的有效着色的最大可能权重为 3131。

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

首页