P14631 [2018 KAIST RUN Fall] Repetitive Palindrome

· · 题解

P14631 [2018 KAIST RUN Fall] Repetitive Palindrome

solution

注意到 1 \le k \le 10^{18},所以模拟显然不可行。

仔细分析。

如果字符串 s 不是一个回文串,那么无论重复几次连接成新串 t,那么 t 一定不是个回文串。而如果字符串 s 是一个回文串,那么连接成的新串 t 一定是个回文串。

所以本题中的 k 可以直接忽略,如果字符串 s 为回文串,则输出 YES;否则输出 NO

AC code

#include <bits/stdc++.h>
#define debug(a) cerr << (#a) << " = " << (a) << endl;
#define int long long
#define maxn 100010
#define endl '\n'
using namespace std;

int k;
string s;
void solve() {
    for (int i = 0; i < s.size() / 2; i++) {
        if (s[i] != s[s.size() - i - 1]) {
            cout << "NO" << endl;
            exit(0);
        }
    }
    cout << "YES" << endl;
}
signed main() {
    cin >> s >> k;
    solve();
    return 0;
}

其它

码字不易,求赞喵!