QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#396311 | #2840. 绿绿与串串 | ucup-team1251 | TL | 1ms | 3568kb | C++20 | 1.9kb | 2024-04-22 17:23:18 | 2024-04-22 17:23:19 |
Judging History
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";
}
}
Details
Tip: Click on the bar to expand more detailed information
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...