A15680 | Triangle Coloring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an undirected graph consisting of $n$ vertices and $n$ edges, where $n$ is divisible by $6$ . Each edge has a weight, which is a positive (greater than zero) integer.
The graph has the following structure: it is split into $\frac{n}{3}$ triples of vertices, the first triple consisting of vertices $1, 2, 3$ , the second triple consisting of vertices $4, 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 $\frac{n}{2}$ red vertices and $\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 $W$ be the maximum possible weight of a valid coloring. Calculate the number of valid colorings with weight $W$ , and print it modulo $998244353$ .
The graph has the following structure: it is split into $\frac{n}{3}$ triples of vertices, the first triple consisting of vertices $1, 2, 3$ , the second triple consisting of vertices $4, 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 $\frac{n}{2}$ red vertices and $\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 $W$ be the maximum possible weight of a valid coloring. Calculate the number of valid colorings with weight $W$ , and print it modulo $998244353$ .
输入格式
The first line contains one integer $n$ ( $6 \le n \le 3 \cdot 10^5$ , $n$ is divisible by $6$ ).
The second line contains $n$ integers $w_1, w_2, \dots, w_n$ ( $1 \le w_i \le 1000$ ) — the weights of the edges. Edge $1$ connects vertices $1$ and $2$ , edge $2$ connects vertices $1$ and $3$ , edge $3$ connects vertices $2$ and $3$ , edge $4$ connects vertices $4$ and $5$ , edge $5$ connects vertices $4$ and $6$ , edge $6$ connects vertices $5$ and $6$ , and so on.
The second line contains $n$ integers $w_1, w_2, \dots, w_n$ ( $1 \le w_i \le 1000$ ) — the weights of the edges. Edge $1$ connects vertices $1$ and $2$ , edge $2$ connects vertices $1$ and $3$ , edge $3$ connects vertices $2$ and $3$ , edge $4$ connects vertices $4$ and $5$ , edge $5$ connects vertices $4$ and $6$ , edge $6$ connects vertices $5$ and $6$ , and so on.
输出格式
Print one integer — the number of valid colorings with maximum possible weight, taken modulo $998244353$ .
输入输出样例
输入 #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 $31$ .
The maximum possible weight of a valid coloring of this graph is $31$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted