| 记录编号 |
560898 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
| 题目名称 |
2566.[51nod 1129] 字符串最大值 |
最终得分 |
100 |
| 用户昵称 |
yrtiop |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
0.038 s |
| 提交时间 |
2021-05-20 21:16:57 |
内存使用 |
2.64 MiB |
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1000005;
char s[maxn];
int cnt[maxn],next[maxn];
long long ans = 0;
int main() {
freopen("string_maxval.in","r",stdin);
freopen("string_maxval.out","w",stdout);
scanf("%s",s + 1);
int len = strlen(s + 1);
next[1] = 0;
for(int i = 2,j = 0;i <= len;++ i) {
while(j&&s[i] != s[j + 1])j = next[j];
if(s[i] == s[j + 1])++ j;
next[i] = j;
}
for(int i = len;i;-- i) {
++ cnt[i];
cnt[next[i]] += cnt[i];
ans = max(ans , (long long)(cnt[i] * i));
}
printf("%lld",ans);
fclose(stdin);
fclose(stdout);
return 0;
}