이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
int p=-1, ch;
string s;
struct node{
node* c[27];
node* fail[27];
vector<node*> nxt;
int cnt, len;
node(){
cnt=0; len=-1;
fox(l, 26){c[l]=fail[l]=0;}
nxt=vector<node*>();
}
node(node*P){
//cout << "^" << P->len << endl;
len=0; cnt=0;
fox(l, 26) c[l]=0;
P->nxt.pb(this);
fox(l, 26){
fail[l]=P;
}
}
node(node*P, int L){
//cout << "&";
len=L; cnt=0;
fox(l, 26) c[l]=0;
if (L>1){
P=P->fail[ch];
while(p-1-P->len<0 || s[p-1-P->len]!=s[p]) P=P->fail[ch];
P=P->c[ch];
}
P->nxt.pb(this);
fox(l, 26){
if (s[p-P->len]-'a'==l) fail[l]=P;
else fail[l]=P->fail[l];
}
}
}*root, *r2, *last;
void add(node*N){
while(p-1-N->len<0 || s[p-1-N->len]!=s[p]){
N=N->fail[ch];
}
//cout << "*" << N->len << endl;
if (N->c[ch]==0){
if (N->len==-1) N->c[ch]=new node(r2, 1);
else N->c[ch]=new node(N, N->len+2);
}
last=N->c[ch];
N->c[ch]->cnt++;
}
ll ans;
void dfs(node*N){
fox(l, N->nxt.size()){
dfs(N->nxt[l]);
N->cnt+=N->nxt[l]->cnt;
}
ans=max(ans, 1LL*N->cnt*N->len);
}
int main(){
root=new node();
last=r2=new node(root);
cin >> s;
for(p=0; p<s.size(); ++p){
ch=s[p]-'a';
add(last);
//cout << p << endl;
}
dfs(root);
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'void dfs(node*)':
palindrome.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
^
palindrome.cpp:81:5: note: in expansion of macro 'fox'
fox(l, N->nxt.size()){
^
palindrome.cpp: In function 'int main()':
palindrome.cpp:91:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(p=0; p<s.size(); ++p){
^
# | 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... |