0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

#166. 【模板】manacher算法

https://sjzezoj.com/submission/64186
This commit is contained in:
Baoshuo Ren 2022-11-12 11:34:08 +08:00
parent e02599f1c4
commit 18c4725259
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
24 changed files with 115 additions and 0 deletions

46
S2OJ/166/166.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <iostream>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1.1e7 + 5;
int p[N << 1], mid, r, ans;
std::string s1, s2;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> s1;
// Init
s2.push_back('^');
for (const char &c : s1) {
s2.push_back('#');
s2.push_back(c);
}
s2 += "#$";
for (int i = 1; i < s2.size(); i++) {
p[i] = i < r ? std::min(p[mid * 2 - i], r - i) : 1;
while (s2[i - p[i]] == s2[i + p[i]]) p[i]++;
if (i + p[i] > r) {
r = i + p[i];
mid = i;
}
}
for (int i = 0; i < s2.size(); i++) {
ans = std::max(ans, p[i]);
}
cout << ans - 1 << endl;
return 0;
}

BIN
S2OJ/166/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/std.cpp (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/str9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/166/data/val.cpp (Stored with Git LFS) Normal file

Binary file not shown.