Skip to content

Commit 099f65f

Browse files
authored
Merge pull request #1586 from AlgorithmWithGod/khj20006
[20251205] BOJ / P5 / 가장 긴 팰린드롬 부분 문자열 / 권혁준
2 parents f3a0253 + b4f51aa commit 099f65f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
string t, s = "#";
6+
int A[222222]{}, C = 1, R = 1;
7+
8+
int main() {
9+
cin.tie(0)->sync_with_stdio(0);
10+
11+
cin >> t;
12+
for (char i : t) s += i, s += "#";
13+
14+
int ans = 0;
15+
for (int i = 1; i < s.size(); i++) {
16+
A[i] = min(A[2 * C - i], R - i);
17+
while (i > A[i] && i + A[i] + 1 < s.size() && s[i - A[i] - 1] == s[i + A[i] + 1]) A[i]++;
18+
if (i + A[i] >= R) C = i, R = i + A[i];
19+
ans = max(ans, A[i]);
20+
}
21+
cout << ans;
22+
23+
}
24+
```

0 commit comments

Comments
 (0)