A9796 | Om Nom and Necklace
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
One day Om Nom found a thread with $n$ beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.
Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular pattern. A sequence of beads $S$ is regular if it can be represented as $S=A+B+A+B+A+...+A+B+A$ , where $A$ and $B$ are some bead sequences, " $+$ " is the concatenation of sequences, there are exactly $2k+1$ summands in this sum, among which there are $k+1$ " $A$ " summands and $k$ " $B$ " summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind if $A$ or $B$ is an empty sequence.
Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form a regular pattern. When Om Nom cuts off the beads, he doesn't change their order.
Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular pattern. A sequence of beads $S$ is regular if it can be represented as $S=A+B+A+B+A+...+A+B+A$ , where $A$ and $B$ are some bead sequences, " $+$ " is the concatenation of sequences, there are exactly $2k+1$ summands in this sum, among which there are $k+1$ " $A$ " summands and $k$ " $B$ " summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind if $A$ or $B$ is an empty sequence.
Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form a regular pattern. When Om Nom cuts off the beads, he doesn't change their order.
输入格式
The first line contains two integers $n$ , $k$ ( $1<=n,k<=1000000$ ) — the number of beads on the thread that Om Nom found and number $k$ from the definition of the regular sequence above.
The second line contains the sequence of $n$ lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter.
The second line contains the sequence of $n$ lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter.
输出格式
Print a string consisting of $n$ zeroes and ones. Position $i$ ( $1<=i<=n$ ) must contain either number one if the first $i$ beads on the thread form a regular sequence, or a zero otherwise.
输入输出样例
输入 #1
7 2 bcabcab
输出 #1
0000011
输入 #2
21 2 ababaababaababaababaa
输出 #2
000110000111111000011
In the first sample test a regular sequence is both a sequence of the first 6 beads (we can take $A=$ "", $B=$ "bca"), and a sequence of the first 7 beads (we can take $A=$ "b", $B=$ "ca").
In the second sample test, for example, a sequence of the first 13 beads is regular, if we take $A=$ "aba", $B=$ "ba".
In the second sample test, for example, a sequence of the first 13 beads is regular, if we take $A=$ "aba", $B=$ "ba".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted