Submission #157660

# Submission time Handle Problem Language Result Execution time Memory
157660 2019-10-12T16:54:31 Z sadmanrizwan Palindromes (APIO14_palindrome) C++14
100 / 100
108 ms 50552 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=300005;
struct node{
    int len,link,cnt;
    map <char,int> to;
};
node pt[MX];
int size,last;
char s[MX];
bool vis[MX];
vector <int> idx[MX];
void init_node(int n)
{
    pt[n].len=0;
    pt[n].cnt=0;
    pt[n].link=-1;
    pt[n].to.clear();
}
void init_pt()
{
    init_node(0);
    init_node(1);
    pt[0].len=pt[0].link=-1;
    pt[1].link=0;
    size=2,last=1;
}
int find(int n,char s[],int i)
{
    while(n){
        int j=i-pt[n].len-1;
        if(j>=0 && s[i]==s[j]) return n;
        n=pt[n].link;
    }
    return n;
}
void extend(char s[],int i)
{
    int n=find(last,s,i);
    if(pt[n].to.count(s[i])==0){
        int m=size++;
        init_node(m);
        pt[n].to[s[i]]=m;
        pt[m].len=pt[n].len+2;
        if(pt[m].len==1) pt[m].link=1;
        else{
            int v=find(pt[n].link,s,i);
            pt[m].link=pt[v].to[s[i]];
        }
        last=m;
    }
    else last=pt[n].to[s[i]];
}
int main()
{
    scanf("%s",s);
    int n=strlen(s);
    init_pt();
    for(int i=0;i<n;i++){
        extend(s,i);
        pt[last].cnt++;
        if(vis[last]) continue;
        vis[last]=true;
        idx[pt[last].len].push_back(last);
    }
    for(int i=n;i>0;i--){
        int l=idx[i].size();
        for(int j=0;j<l;j++){
            int v=idx[i][j];
            int u=pt[v].link;
            if(u>1) pt[u].cnt+=pt[v].cnt;
        }
    }
    ll ans=0;
    for(int i=2;i<size;i++){
        ans=max(ans,(ll)pt[i].cnt*(ll)pt[i].len);
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",s);
     ~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 26104 KB Output is correct
2 Correct 26 ms 26232 KB Output is correct
3 Correct 26 ms 26104 KB Output is correct
4 Correct 26 ms 26104 KB Output is correct
5 Correct 26 ms 26144 KB Output is correct
6 Correct 26 ms 26108 KB Output is correct
7 Correct 26 ms 26104 KB Output is correct
8 Correct 26 ms 26132 KB Output is correct
9 Correct 26 ms 26232 KB Output is correct
10 Correct 25 ms 26104 KB Output is correct
11 Correct 26 ms 26104 KB Output is correct
12 Correct 25 ms 26104 KB Output is correct
13 Correct 26 ms 26148 KB Output is correct
14 Correct 25 ms 26104 KB Output is correct
15 Correct 26 ms 26104 KB Output is correct
16 Correct 25 ms 26108 KB Output is correct
17 Correct 26 ms 26104 KB Output is correct
18 Correct 27 ms 26280 KB Output is correct
19 Correct 26 ms 26104 KB Output is correct
20 Correct 26 ms 26232 KB Output is correct
21 Correct 26 ms 26104 KB Output is correct
22 Correct 26 ms 26232 KB Output is correct
23 Correct 26 ms 26104 KB Output is correct
24 Correct 27 ms 26232 KB Output is correct
25 Correct 25 ms 26232 KB Output is correct
26 Correct 26 ms 26104 KB Output is correct
27 Correct 26 ms 26108 KB Output is correct
28 Correct 26 ms 26104 KB Output is correct
29 Correct 26 ms 26104 KB Output is correct
30 Correct 27 ms 26232 KB Output is correct
31 Correct 26 ms 26104 KB Output is correct
32 Correct 26 ms 26108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 26212 KB Output is correct
2 Correct 26 ms 26228 KB Output is correct
3 Correct 26 ms 26232 KB Output is correct
4 Correct 30 ms 26104 KB Output is correct
5 Correct 26 ms 26232 KB Output is correct
6 Correct 27 ms 26360 KB Output is correct
7 Correct 26 ms 26204 KB Output is correct
8 Correct 26 ms 26232 KB Output is correct
9 Correct 25 ms 26232 KB Output is correct
10 Correct 25 ms 26196 KB Output is correct
11 Correct 26 ms 26232 KB Output is correct
12 Correct 26 ms 26204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 26872 KB Output is correct
2 Correct 28 ms 26872 KB Output is correct
3 Correct 28 ms 26936 KB Output is correct
4 Correct 28 ms 26872 KB Output is correct
5 Correct 28 ms 26744 KB Output is correct
6 Correct 28 ms 26744 KB Output is correct
7 Correct 28 ms 26744 KB Output is correct
8 Correct 26 ms 26232 KB Output is correct
9 Correct 27 ms 26232 KB Output is correct
10 Correct 27 ms 26488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 32760 KB Output is correct
2 Correct 45 ms 31992 KB Output is correct
3 Correct 47 ms 34268 KB Output is correct
4 Correct 48 ms 33264 KB Output is correct
5 Correct 46 ms 32348 KB Output is correct
6 Correct 40 ms 30584 KB Output is correct
7 Correct 43 ms 31564 KB Output is correct
8 Correct 32 ms 26364 KB Output is correct
9 Correct 36 ms 28280 KB Output is correct
10 Correct 44 ms 31480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 45868 KB Output is correct
2 Correct 93 ms 43680 KB Output is correct
3 Correct 89 ms 50552 KB Output is correct
4 Correct 92 ms 45532 KB Output is correct
5 Correct 90 ms 45816 KB Output is correct
6 Correct 82 ms 42556 KB Output is correct
7 Correct 76 ms 41080 KB Output is correct
8 Correct 45 ms 26872 KB Output is correct
9 Correct 47 ms 26872 KB Output is correct
10 Correct 80 ms 42616 KB Output is correct
11 Correct 108 ms 45904 KB Output is correct
12 Correct 49 ms 28944 KB Output is correct