# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1150630 | SmuggingSpun | 회문 (APIO14_palindrome) | C++20 | 0 ms | 324 KiB |
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
template<class T>void maximize(T& a, T b){
if(a < b){
a = b;
}
}
string s;
ll ans = 0;
struct Node{
int link, len, cnt, child[26];
Node(){
memset(this->child, -1, sizeof(this->child));
this->cnt = 1;
}
};
vector<Node>eer(2);
void dfs(int s){
for(int i = 0; i < 26; i++){
if(eer[s].child[i] != -1){
dfs(eer[s].child[i]);
}
}
eer[eer[s].link].cnt += eer[s].cnt;
maximize(ans, 1LL * eer[s].cnt * eer[s].len);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
eer[eer[1].len = eer[0].link = eer[1].link = 0].len = -1;
cin >> s;
for(int i = 0, root = 0; i < s.size(); i++){
s[i] -= 97;
while(s[i] != s[i - eer[root].len - 1]){
root = eer[root].link;
}
if(eer[root].child[s[i]] == -1){
int cur = eer[root].child[s[i]] = eer.size();
eer.emplace_back(Node());
eer[cur].len = eer[root].len + 2;
root = eer[root].link;
while(root != 0 && eer[root].child[s[i]] == -1){
root = eer[root].link;
}
eer[cur].link = (eer[cur].len == 1 || eer[root].child[s[i]] == -1 ? 1 : eer[root].child[s[i]]);
root = cur;
}
else{
eer[root = eer[root].child[s[i]]].cnt++;
}
}
dfs(0);
dfs(1);
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |