제출 #21912

#제출 시각아이디문제언어결과실행 시간메모리
21912Yousef_Salama회문 (APIO14_palindrome)C++11
0 / 100
106 ms67812 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; char s[MAXN]; int N; int suflink[MAXN], g[MAXN][26], length[MAXN], flag[MAXN], M, p; vector <int> G[MAXN]; void init(){ memset(suflink, -1, sizeof suflink); memset(g, -1, sizeof g); length[0] = -1; length[1] = 0; suflink[1] = 0; G[0].push_back(1); M = 2; p = 1; } void extend(int i){ while((i - length[p] - 1 < 0) || (s[i] != s[i - length[p] - 1])) p = suflink[p]; if(g[p][s[i] - 'a'] != -1){ flag[g[p][s[i] - 'a']]++; p = g[p][s[i] - 'a']; }else{ int q = M++; g[p][s[i] - 'a'] = q; length[q] = length[p] + 2; while(true){ if(p == 0){ suflink[q] = 1; break; } p = suflink[p]; if(g[p][s[i] - 'a'] != -1){ suflink[q] = g[p][s[i] - 'a']; break; } } G[suflink[q]].push_back(q); flag[q]++; p = q; } } int occ[MAXN]; long long solve(int i){ occ[i] = flag[i]; long long r = 0; for(int j : G[i]){ r = max(r, solve(j)); occ[i] += occ[j]; } r = max(r, (long long)occ[i] * length[i]); return r; } int main(){ scanf("%s", s); N = strlen(s); init(); for(int i = 0; i < N; i++) extend(i); printf("%lld\n", solve(0)); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

palindrome.cpp: In function 'int main()':
palindrome.cpp:73:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s);
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...