이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int,int>;
#define ff first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
const int mx = 1e6 + 5;
int tree[mx][26], idx;
char s[mx]; int ans[mx];
int len[mx], link[mx], t, occ[mx];
void init(){
memset(ans, 0, sizeof ans);
memset(occ, 0, sizeof occ);
memset(tree, 0, sizeof tree);
len[1] = -1; link[1] = 1;
len[2] = 0; link[2] = 1;
idx = t = 2;
}
void extend(int p){
while(s[p-len[t]-1] != s[p]) t=link[t];
int x = link[t], c = s[p] - 'a';
while(s[p-len[x]-1] != s[p]) x=link[x];
if(!tree[t][c]){
tree[t][c] = ++idx;
len[idx] = len[t] + 2;
link[idx] = len[idx] == 1 ? 2 : tree[x][c];
ans[idx] = 1 + ans[link[idx]];
}t = tree[t][c]; ++occ[t];
}
ll solve(){
int n = strlen(s);
for(int i=0; i<n; ++i) extend(i);
for(int i=idx; i>2; --i)
occ[link[i]] += occ[i];
ll ans = 0;
for(int i=2; i<=idx; ++i)
ans = max(ans, 1LL*len[i]*occ[i]);
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int q = 1; // cin >> q;
for(int cs=1; cs<=q; ++cs){
cin >> s; init();
cout << solve() << "\n";
}
return 0;
}
# | 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... |