Codeforces Round #305 (Div. 二)- Mike and Fax(分段找回文串)

Codeforces Round #305 (Div. 2)- Mike and Fax(分段找回文串)

Mike and Fax
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.

Codeforces Round #305 (Div. 二)- Mike and Fax(分段找回文串)

He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.

He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.

Input

The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000).

The second line contains integer k (1 ≤ k ≤ 1000).

Output

Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.

Sample test(s)
input
saba
2
output
NO
input
saddastavvat
2
output
YES
题意:一个字符串,有k个子串,问这k个子串是不是回文串。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double eps=1e-10;
const double pi= acos(-1.0);
char str[1010];
int main() {
    int k,i,j;
    int flag;
    scanf("%s",str);
    scanf("%d",&k);
    flag=0;
    int len=strlen(str);
    if(len%k)
        puts("NO\n");
    else {
        int cnt=len/k;
        for(i=0; i<len; i+=cnt) {
            for(j=0; j<cnt/2; j++) {
                if(str[i+j]!=str[cnt+i-j-1]) {
                    flag=1;
                    break;
                }
            }
            if(flag) break;
        }
        if(flag)
            puts("NO");
        else
            puts("YES");
    }
    return 0;
}