mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:48:48 +00:00
parent
a0e921f847
commit
b0db86725c
84
S2OJ/574/574.cpp
Normal file
84
S2OJ/574/574.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
std::vector<int> manacher(const std::string &_s) {
|
||||
int n = _s.size();
|
||||
std::string s(n * 2 + 3, '#');
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
s[i * 2 + 2] = _s[i];
|
||||
}
|
||||
|
||||
s[0] = '^';
|
||||
s[n * 2 + 2] = '$';
|
||||
|
||||
std::vector<int> p(s.size(), 1);
|
||||
|
||||
for (int i = 1, mid = 0, r = 0; i <= n * 2 + 1; i++) {
|
||||
p[i] = i < r ? std::min(p[mid * 2 - i], r - i) : 1;
|
||||
|
||||
while (s[i - p[i]] == s[i + p[i]]) p[i]++;
|
||||
|
||||
if (i + p[i] - 1 > r) {
|
||||
r = i + p[i] - 1;
|
||||
mid = i;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
p[i] = p[i * 2 + 2] / 2;
|
||||
}
|
||||
|
||||
p.resize(n);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
std::string s;
|
||||
|
||||
cin >> s;
|
||||
|
||||
int n = s.size();
|
||||
|
||||
if (n == 1) {
|
||||
cout << 1 << endl;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
auto p = manacher(s);
|
||||
std::vector<int> ans(n);
|
||||
|
||||
for (int i = n - 1; i >= 0; --i) {
|
||||
if (i * 2 < n) {
|
||||
ans[i] = (p[i] >= i + 1) && ans[i * 2];
|
||||
} else {
|
||||
ans[i] = p[i] >= n - i;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (ans[i]) {
|
||||
cout << (i + 1) << ' ';
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/574/data/ex_string1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/ex_string1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/ex_string1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/ex_string1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/574/data/string9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/574/data/string9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user