A15961 | Bosco and Particle
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Bosco is studying the behaviour of particles. He decided to investigate on the peculiar behaviour of the so-called "four-one-two" particle. He does the following:
There is a line of length $n+1$ , where the topmost point is position $0$ and bottommost is position $n+1$ . The particle is initially (at time $t=0$ ) at position $0$ and heading downwards. The particle moves at the speed of $1$ unit per second. There are $n$ oscillators at positions $1,2,\ldots,n$ .
Each oscillator can be described by a binary string. The initial state of each oscillator is the first character of its binary string. When the particle hits with an oscillator, the particle reverses its direction if its current state is $\texttt{1}$ and continues to move at the same direction if its current state is $\texttt{0}$ , and that oscillator moves on to the next state (the next state of the last state is defined as the first state). Additionally, the particle always reverses its direction when it is at position $0$ or $n+1$ at time $t > 0$ .
Bosco would like to know the cycle length of the movement of particle. The cycle length is defined as the minimum value of $c$ such that for any time $t \ge 0$ , the position of the particle at time $t$ is same as the position of the particle at time $t+c$ . It can be proved that such value $c$ always exists. As he realises the answer might be too large, he asks you to output your answer modulo $998244353$ .
There is a line of length $n+1$ , where the topmost point is position $0$ and bottommost is position $n+1$ . The particle is initially (at time $t=0$ ) at position $0$ and heading downwards. The particle moves at the speed of $1$ unit per second. There are $n$ oscillators at positions $1,2,\ldots,n$ .
Each oscillator can be described by a binary string. The initial state of each oscillator is the first character of its binary string. When the particle hits with an oscillator, the particle reverses its direction if its current state is $\texttt{1}$ and continues to move at the same direction if its current state is $\texttt{0}$ , and that oscillator moves on to the next state (the next state of the last state is defined as the first state). Additionally, the particle always reverses its direction when it is at position $0$ or $n+1$ at time $t > 0$ .
Bosco would like to know the cycle length of the movement of particle. The cycle length is defined as the minimum value of $c$ such that for any time $t \ge 0$ , the position of the particle at time $t$ is same as the position of the particle at time $t+c$ . It can be proved that such value $c$ always exists. As he realises the answer might be too large, he asks you to output your answer modulo $998244353$ .
输入格式
The first line contains an integer $n$ ( $1\le n\le10^6$ ) — the number of oscillators.
The $i$ -th of the next $n$ line contains a binary string $s_i$ ( $1\le\left|s_i\right|\le10^6$ ) — the binary string, that contains only characters $\texttt{0}$ and $\texttt{1}$ , describing the oscillator at position $i$ .
It is guaranteed that the sum of all $|s_i|$ does not exceed $10^6$ .
The $i$ -th of the next $n$ line contains a binary string $s_i$ ( $1\le\left|s_i\right|\le10^6$ ) — the binary string, that contains only characters $\texttt{0}$ and $\texttt{1}$ , describing the oscillator at position $i$ .
It is guaranteed that the sum of all $|s_i|$ does not exceed $10^6$ .
输出格式
Output a single integer integer — the cycle length of the movement of the particle, modulo $998244353$ .
输入输出样例
输入 #1
1 00
输出 #1
4
输入 #2
2 01 010
输出 #2
16
输入 #3
4 0101 000 1 01
输出 #3
12
输入 #4
4 01010 0001 11 0001
输出 #4
120
In the first sample, the only oscillator at position $1$ always has state $\texttt{0}$ . At time moments $0,1,2,3$ positions the particle are $0,1,2,1$ respectively. Then the same positions will be repeated, so $c=4$ .
Animation for the second sample: [here](https://u.cubeupload.com/culver0412/GJ5PNy.png) or [a smoother animation](https://i.imgur.com/X35t71G.gif).
Animation for the second sample: [here](https://u.cubeupload.com/culver0412/GJ5PNy.png) or [a smoother animation](https://i.imgur.com/X35t71G.gif).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted