QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#396311#2840. 绿绿与串串ucup-team1251TL 1ms3568kbC++201.9kb2024-04-22 17:23:182024-04-22 17:23:19

Judging History

你现在查看的是最新测评结果

  • [2024-04-22 17:23:19]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3568kb
  • [2024-04-22 17:23:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
string s, rs;
int mlc[N];
void init(string s)
{
    string str;
    str = "!#";
    for (int i = 0; s[i]; i++)
        str = str + s[i] + '#';
    str = str + '\0';
    int idx = 0, mx = 0;
    for (int i = 0; i < str.length(); i++)
    {
        if (mx > i)
            mlc[i] = min(mlc[2 * idx - i], mx - i);
        else
            mlc[i] = 1;
        while (str[i + mlc[i]] == str[i - mlc[i]])
            mlc[i]++;
        if (i + mlc[i] > mx)
        {
            mx = i + mlc[i];
            idx = i;
        }
    }
}
bool check(int cnt)
{
    if (cnt >= s.size())
        return 0;
    int pos = s.size() - cnt, len = s.size() - cnt;
    if (s.substr(cnt, len) == rs.substr(pos, len))
        return 1;
    return 0;
}
int main()
{
    ios::sync_with_stdio(0);
    int T = 1;
    cin >> T;
    while (T--)
    {
        cin >> s;
        if (s.size() == 1)
        {
            cout << "1\n";
            continue;
        }
        init(s);
unordered_map<int, int> memo;
        rs = string(s.rbegin(), s.rend());
        s = ' ' + s;
        rs = ' ' + rs;
        int n = s.size() - 1;
        for (int i = 2; i < s.size(); i++)
        {
            if (memo.count(i))
            {
                cout << i << ' ';
                continue;
            }
            int fg = 1, cnt = i;
            while (cnt <= n / 2)
            {
                if (mlc[cnt * 2] != 2 * cnt)
                {
                    fg = 0;
                    break;
                }
                cnt = cnt * 2 - 1;
            }
            if (fg && check(cnt))
            {
                int ii = i;
                while (ii <= n)
                {
                    memo[ii] = 1;
                    ii = ii * 2 - 1;
                }
                cout << i << ' ';
            }
        }
        cout << "\n";
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3568kb

input:

7
abcdcb
qwqwq
qaqaqqq
carnation
c
ab
aa

output:

4 6 
2 3 4 5 
6 7 
9 
1
2 
2 

result:

ok 7 lines

Test #2:

score: -100
Time Limit Exceeded

input:

5
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:


result: