嘟嘟嘟

我们可以把AB看成S,则要找的串可以写成SSSSA或者SSSSS。假设S出现了Q次,那么A出现了Q % k次,则B出现了 Q / k - Q % k次.

当ABABA是SSS的形式时,B可以为空字符,判断Q / k - Q % k>=0。

当ABABA是SSA的形式时,判断Q / k - Q % k > 0。

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1e6 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), las = ' ';
while(!isdigit(ch)) las = ch, ch = getchar();
while(isdigit(ch)) ans = ans * + ch - '', ch = getchar();
if(las == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar(x % + '');
} int n, k;
char s[maxn];
int f[maxn]; void init()
{
for(int i = , j = ; i <= n; ++i)
{
while(j && s[j + ] != s[i]) j = f[j];
if(s[j + ] == s[i]) j++;
f[i] = j;
}
} bool work(int i, int cir)
{
int x = i / cir;
if(i % cir) return x / k > x % k;
else return x / k >= x % k;
} int main()
{
n = read(), k = read();
scanf("%s", s + );
init();
for(int i = ; i <= n; ++i) write(work(i, i - f[i]));
enter;
return ;
}

CF526D Om Nom and Necklace的更多相关文章

  1. Codeforces 526D - Om Nom and Necklace 【KMP】

    ZeptoLab Code Rush 2015 D. Om Nom and Necklace [题意] 给出一个字符串s,判断其各个前缀是否是 ABABA…ABA的形式(A和B都可以为空,且A有Q+1 ...

  2. Codeforces - ZeptoLab Code Rush 2015 - D. Om Nom and Necklace:字符串

    D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Codeforces 526.D Om Nom and Necklace

    D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. 【Codeforces 526D】Om Nom and Necklace

    Codeforces 526 D 题意:给一个字符串,求每个前缀是否能表示成\(A+B+A+B+\dots+A\)(\(k\)个\(A+B\))的形式. 思路1:求出所有前缀的哈希值,以便求每个子串的 ...

  5. Codeforces 526D Om Nom and Necklace (KMP)

    http://codeforces.com/problemset/problem/526/D 题意 给定一个串 T,对它的每一个前缀能否写成 A+B+A+B+...+B+A+B+A+B+...+B+A ...

  6. Codeforces ZeptoLab Code Rush 2015 D.Om Nom and Necklace(kmp)

    题目描述: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色的宝石.他决定摘取前面若干个宝石来做成一个漂亮的项链. 他对漂亮的项链是这样定义的,现在有一条项链S,当S=A+B+A+B+A+. ...

  7. 【Henu ACM Round#16 F】Om Nom and Necklace

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] KMP算法可以把"i前缀"pre[i] 分成ssssst的形式 这里t是s的前缀. 然后s其实就是pre[i]中 ...

  8. CodeForces 526D Om Nom and Necklace

    洛谷题目页面传送门 & CodeForces题目页面传送门 给定字符串\(a\),求它的每一个前缀,是否能被表示成\(m+1\)个字符串\(A\)和\(m\)个字符串\(B\)交错相连的形式, ...

  9. Zepto Code Rush 2014 B - Om Nom and Spiders

    注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...

随机推荐

  1. Ionic3,关于配置公共的css文件,引用非标准的文件(三)

    说明 在开发过程中,很多样式为了能够共用,这样能够节省很大一部分时间用来编写样式,同时,一个完整的共用模板,在进行样式更换的时候,可以达到事半功倍的效果,因此在开发效率上也可以获得提高. 相关步骤: ...

  2. org.hibernate.QueryException: duplicate alias: r hibernate别名重复问题解决

    今天做项目的过程中发现,多表查询的时候如果使用hibernate的DetachedCriteria离线查询方式的时候, 在多表关联的时候我们需要使用别名的方式去实现. 但是代码运行的过程中抛出了下面的 ...

  3. 线程同步(windows平台):互斥对象

    一:介绍 互斥对象是系统内核维护的一种数据结构,保证了对象对单个线程的访问权. 二:函数说明 创建互斥对象:    HANDLE CreateMutex(            LPSECURITY_ ...

  4. 用PHP实现同一个帐号不允许同时登陆,只允许一个帐号登录?

    数据库表 user_login_info 字段:id,user_ip,user_id,last_access_time user_id 做唯一性索引 1. 用户登录后 如果没有当前用户的数据,插入一条 ...

  5. js 获取 Url.Action 设置area

    var url = '@Url.Action("UserEdit","User",new { Area = "Setup", id = 1} ...

  6. indexOf.substr,substring,charAt的区别

    var a = "asdfghjkl" alert(a.substr(1, 3));        //  从下标为1开始,往右数3个长度的数, 显示 sdf; alert(a.s ...

  7. artDialog组件应用学习(一)

    个人觉得artDialog是一组很不错的对话框组件.写的是artDialog_v6应用. 官方称其兼容性测试通过:IE6~IE11.Chrome.Firefox.Safari.Opera. 官网:ht ...

  8. scss-null在@mixin传参中的应用

    可以给混合器声明参数,以便灵活的配置相关属性值,看如下scss代码: @mixin antzone-div($color, $font-size) { color:$color; font-size: ...

  9. Android开发之EditText利用键盘跳转到下一个输入框

    以前做项目的时候,从来没考虑过这些.这段时间公司内部用的一款APP,就出现了这个问题,在登录或者注册的时候,点击键盘的回车按钮,可以跳到下一个输入框的功能,这个属性一直也没记住,今天就把自己一直没记过 ...

  10. webstorm上传vue代码至git

    Git在push时候,提示:push to origin/master was rejected 解决方案如下: 提交代码顺序 webstorm右键项目名称==>Git==>Commit ...