답안 #549642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549642 2022-04-16T07:42:14 Z krit3379 회문 (APIO14_palindrome) C++17
100 / 100
38 ms 39124 KB
#include<bits/stdc++.h>
using namespace std;
#define N 300005

struct node{
    int nxt[26];
    int deg;
    int len;
    int suff;
    long long cnt;
}t[N];

int num,suff;
long long ans;
string s;
queue<int> q;

void add(int pos){
    int cur=suff,idx=s[pos]-'a';
    while(true){
        if(pos-t[cur].len-1>=0&&s[pos-t[cur].len-1]==s[pos])break;
        cur=t[cur].suff;
    }
    if(t[cur].nxt[idx]){
        suff=t[cur].nxt[idx];
        t[suff].cnt++;
        return ;
    }
    t[cur].nxt[idx]=++num;
    t[num].len=t[cur].len+2;
    t[num].cnt++;
    suff=num;
    if(t[num].len==1){
        t[num].suff=2;
        return ;
    }
    while(true){
        cur=t[cur].suff;
        if(pos-t[cur].len-1>=0&&s[pos-t[cur].len-1]==s[pos])break;
    }
    t[num].suff=t[cur].nxt[idx];
    t[t[num].suff].deg++;
}

void init(){
    num=2,suff=2;
    t[1].len=-1,t[1].suff=1;
    t[2].len=0,t[2].suff=1;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int i,a;
    cin>>s;
    init();
    for(i=0;i<s.length();i++)add(i);
    for(i=3;i<=num;i++)if(!t[i].deg)q.push(i);
    while(!q.empty()){
        a=q.front();
        q.pop();
        if(a<=2)continue;
        t[t[a].suff].cnt+=t[a].cnt;
        if(!--t[t[a].suff].deg)q.push(t[a].suff);
        ans=max(ans,t[a].cnt*t[a].len);
    }
    cout<<ans;
    return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(i=0;i<s.length();i++)add(i);
      |             ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 224 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 224 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 2 ms 1620 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 2 ms 1560 KB Output is correct
5 Correct 2 ms 1596 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 13140 KB Output is correct
2 Correct 10 ms 13140 KB Output is correct
3 Correct 13 ms 13140 KB Output is correct
4 Correct 11 ms 13140 KB Output is correct
5 Correct 12 ms 13268 KB Output is correct
6 Correct 8 ms 9780 KB Output is correct
7 Correct 8 ms 11240 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 4 ms 3508 KB Output is correct
10 Correct 9 ms 11352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 38596 KB Output is correct
2 Correct 38 ms 38512 KB Output is correct
3 Correct 29 ms 38612 KB Output is correct
4 Correct 34 ms 38540 KB Output is correct
5 Correct 35 ms 39124 KB Output is correct
6 Correct 31 ms 34448 KB Output is correct
7 Correct 24 ms 32212 KB Output is correct
8 Correct 6 ms 1244 KB Output is correct
9 Correct 5 ms 1248 KB Output is correct
10 Correct 26 ms 32220 KB Output is correct
11 Correct 37 ms 38620 KB Output is correct
12 Correct 8 ms 4572 KB Output is correct