A15301 | Circular Mirror
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Pak Chanek has a mirror in the shape of a circle. There are $N$ lamps on the circumference numbered from $1$ to $N$ in clockwise order. The length of the arc from lamp $i$ to lamp $i+1$ is $D_i$ for $1 \leq i \leq N-1$ . Meanwhile, the length of the arc between lamp $N$ and lamp $1$ is $D_N$ .
Pak Chanek wants to colour the lamps with $M$ different colours. Each lamp can be coloured with one of the $M$ colours. However, there cannot be three different lamps such that the colours of the three lamps are the same and the triangle made by considering the three lamps as vertices is a right triangle (triangle with one of its angles being exactly $90$ degrees).
The following are examples of lamp colouring configurations on the circular mirror.
Figure 1. an example of an incorrect colouring because lamps $1$ , $2$ , and $3$ form a right triangleFigure 2. an example of a correct colouringFigure 3. an example of a correct colouringBefore colouring the lamps, Pak Chanek wants to know the number of distinct colouring configurations he can make. Count the number of distinct possible lamp colouring configurations, modulo $998\,244\,353$ .
Pak Chanek wants to colour the lamps with $M$ different colours. Each lamp can be coloured with one of the $M$ colours. However, there cannot be three different lamps such that the colours of the three lamps are the same and the triangle made by considering the three lamps as vertices is a right triangle (triangle with one of its angles being exactly $90$ degrees).
The following are examples of lamp colouring configurations on the circular mirror.
Figure 1. an example of an incorrect colouring because lamps $1$ , $2$ , and $3$ form a right triangleFigure 2. an example of a correct colouringFigure 3. an example of a correct colouringBefore colouring the lamps, Pak Chanek wants to know the number of distinct colouring configurations he can make. Count the number of distinct possible lamp colouring configurations, modulo $998\,244\,353$ .
输入格式
The first line contains two integers $N$ and $M$ ( $1 \le N \le 3 \cdot 10^5$ , $2 \le M \le 3 \cdot 10^5$ ) — the number of lamps in the mirror and the number of different colours used.
The second line contains $N$ integers $D_1, D_2, \ldots, D_N$ ( $1 \le D_i \le 10^9$ ) — the lengths of the arcs between the lamps in the mirror.
The second line contains $N$ integers $D_1, D_2, \ldots, D_N$ ( $1 \le D_i \le 10^9$ ) — the lengths of the arcs between the lamps in the mirror.
输出格式
An integer representing the number of possible lamp colouring configurations, modulo $998\,244\,353$ .
输入输出样例
输入 #1
4 2 10 10 6 14
输出 #1
10
输入 #2
1 2 10
输出 #2
2
In the first example, all correct lamp colouring configurations are $[1, 1, 2, 1]$ , $[1, 1, 2, 2]$ , $[1, 2, 1, 2]$ , $[1, 2, 2, 1]$ , $[1, 2, 2, 2]$ , $[2, 1, 1, 1]$ , $[2, 1, 1, 2]$ , $[2, 1, 2, 1]$ , $[2, 2, 1, 1]$ , and $[2, 2, 1, 2]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted