이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
#define ROF(i,j,k) for(int i=j; i>=k; --i)
inline int read (void) {
int x = 0, f = 1, ch = getchar();
while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
using ll = long long;
const int maxn = 300005;
char c[maxn];
int tot, lst, trans[maxn][26], len[maxn], fail[maxn], cnt[maxn];
inline int newnode (int l) {
len[++ tot] = l; return tot;
}
inline void prework (void) {
tot = -1; fail[0] = 1;
newnode (0); newnode (-1);
}
inline int getfail (int x, int pos) {
while(c[pos] != c[pos - len[x] - 1]) x = fail[x];
return x;
}
inline void insert (int pos) {
int x = getfail (lst, pos);
if(!trans[x][c[pos] - 'a']) {
int y = newnode (len[x] + 2);
fail[y] = trans[getfail (fail[x], pos)][c[pos] - 'a'];
trans[x][c[pos] - 'a'] = y;
} lst = trans[x][c[pos] - 'a'];
}
std::vector <int> v[maxn];
ll ans;
void dfs (int x) {
for(auto&it:v[x]) {
dfs (it);
cnt[x] += cnt[it];
}
if(len[x] > 0) ans = std::max(ans, 1ll * len[x] * cnt[x]);
}
int main (void) {
scanf("%s", c+1);
int n = strlen(c+1);
prework ();
FOR(i,1,n) {
insert (i);
++ cnt[lst];
}
FOR(i,2,tot) v[fail[i]].push_back(i);
dfs (0); dfs (1);
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'int main()':
palindrome.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%s", c+1);
| ~~~~~^~~~~~~~~~~
# | 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... |