D. Om Nom and Necklace
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The first line contains two integers nk (1 ≤ n, k ≤ 1 000 000) — the number of beads on the thread that Om Nom found and number kfrom 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.

Output

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.

Examples
input
7 2
bcabcab
output
0000011
input
21 2
ababaababaababaababaa
output
000110000111111000011
Note

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".

大致题意:给一个字符串,问该字符串的[1,i]位上的字符串能不能由A+B+A+B+......+A构成?其中k+1个A,k个B,A,B可以为空串.

分析:分别枚举A,B不大好做,但是AB可以拼起来,原题就变成了能不能用k个AB和1个A拼成,AB作为一个循环节,要先求循环节的长度,利用kmp的next数组得到.最小循环节的t倍还是循环节,记作cir,那么问题就是判断能否存在t使得i / (t * cir) = k或i = (k+1) * t*cir

(A是空串).这个问题就比较简单了,将t用i,cir,k表示,检验t是否>0并且满足条件式子.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, k, nextt[];
char s[]; void init()
{
int j = ;
for (int i = ; i <= n; i++)
{
while (j > && s[j + ] != s[i])
j = nextt[j];
if (s[j + ] == s[i])
j++;
nextt[i] = j;
}
} bool check(int x)
{
int cir = x - nextt[x];
if (x % (k + ) == && (x / (k + )) % cir == )
return true;
int t = x / (k * cir);
if (t > && x / (cir * t) == k)
return true;
return false;
} int main()
{
scanf("%d%d", &n, &k);
scanf("%s", s + );
init();
for (int i = ; i <= n; i++)
{
if (check(i))
printf("");
else
printf("");
} return ;
}

最新文章

  1. js控制台输出console
  2. 《DOM Scripting》 - 阅读笔记
  3. 阿里云推荐码 hut29f
  4. HTML 学习记录
  5. 去除html标签 正则表达式
  6. 未能加载文件或程序集“CefSharp, Version=1.25.XXXX”或它的某一个依赖项。试图加载格式不正确的程序。
  7. 2013 Multi-University Training Contest 10
  8. C#3
  9. Effective C++ 沉思录
  10. IOS开发之NSObject协议类方法说明
  11. 关于找工作(二 Cover Letter)
  12. Xamarin生成的APK大小分析
  13. [转] Chrome 控制台不完全指南
  14. [推荐]ORACLE PL/SQL编程之四:把游标说透(不怕做不到,只怕想不到)
  15. java学习笔记----java入门
  16. 自定义QGraphicsItem
  17. 根据数值获得概率密度pdf和累积密度分布cdf(MATLAB语言)
  18. 本地服务器搭建服务:ftp
  19. Ext3.4--Gridpanel
  20. 【pyhon】理想论坛单帖爬虫取得信息存入MySql数据库

热门文章

  1. oracle数据库之组函数
  2. 修改Linux系统下的最大文件描述符限制
  3. JVM监控及堆栈内存
  4. mac react-native从零开始android真机测试
  5. linux 性能分析命令及其解释
  6. Beta阶段第三次网络会议
  7. Java变量声明,实例化,问题
  8. 团队开发——软件需求分析报告(Hello World 团队)
  9. OOP 1.1 引用
  10. ImportError: No module named examples.tutorials.mnist