Submission #303506

# Submission time Handle Problem Language Result Execution time Memory
303506 2020-09-20T11:18:56 Z mohamedsobhi777 Palindromes (APIO14_palindrome) C++14
0 / 100
57 ms 27320 KB
#include<bits/stdc++.h>

#pragma GCC optimize("-Ofast")
#pragma GCC optimize("trapv")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")

#define pii pair<int,int> 
#define pll Pair<ll,ll>
#define I inline void
#define S struct
#define vi vector<int> 
#define vii vector<pii>


using namespace std ; 
using ll = long long ; 
using ld = long double ; 

const int N = 1e5 + 7 ; 

// How interesting!

int n ; 
int num , suf ; 

string s; 

struct node{
        int nxt[26] ; 
        int num, len, sufLink ; 
        int lazy ; 
} eet[N]; 

bool addL(int pos ){

        int let = s[pos] - 'a' ; 
        int cur = suf, curl = 0 ; 

        while(1){
                curl = eet[cur].len ; 
                if( pos - 1 - curl >= 0 && s[pos -1 - curl] == s[pos]){
                        break ; 
                }

                cur = eet[cur].sufLink ; 
        }

        if(eet[cur].nxt[let]){
                suf = eet[cur].nxt[let] ; 
                return false ;
        }

        suf = ++ num ;
        eet[num].len = eet[cur].len + 2 ; 
        eet[cur].nxt[let] = num ;
        eet[num].lazy = 1;  

        if(eet[num].len == 1){
                eet[num].sufLink = 2 ;
                eet[num].num = 1; 
                return 1 ; 
        }

        while(1){
                cur = eet[cur].sufLink ; 
                curl = eet[cur].len ;
                if( pos - 1 - curl >= 0 && s[pos -1 - curl] == s[pos]){
                        eet[num].sufLink = eet[cur].nxt[let] ;
                        break ; 
                }
        }


        eet[num].num = 1 + eet[eet[num].sufLink].num ; 

        return 1 ; 
}

I init(){
        suf = num = 2 ; 
        eet[1].len = - 1, eet[2].len = 0 ;
        eet[1].sufLink = eet[2].sufLink = 1; 
}

int viz[N]; 

int main(){
        ios_base::sync_with_stdio(0) ; 
        cin.tie(0) ; 
        //freopen("in.in" , "r" ,stdin) ; 
        cin >> s; 
        n = (int) s.size() ;
        init() ; 
        for(int i = 0 ;i < n; i++){
                addL(i) ;
        }

        ll ans = 0 ; 

        priority_queue<int> q ; 
        for(int i = 3 ; i <= num ; ++ i)
                q.push(i) ; 

        while(q.size()){
                int x = q.top(); q.pop() ; 
                if(viz[x]++)
                        continue ; 
                ans = max(ans , 1ll * eet[x].len * eet[x].lazy ) ;
                if(eet[x].sufLink > 2){
                        eet[ eet[x].sufLink ].lazy += eet[x].lazy ; 
                        q.push(eet[x].sufLink) ;
                }
        }

        cout<< ans; 
        return 0 ; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Incorrect 0 ms 384 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Incorrect 0 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1664 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 3 ms 1664 KB Output is correct
4 Correct 3 ms 1664 KB Output is correct
5 Correct 4 ms 1664 KB Output is correct
6 Correct 4 ms 1664 KB Output is correct
7 Correct 3 ms 1664 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13364 KB Output is correct
2 Correct 30 ms 13364 KB Output is correct
3 Correct 30 ms 13372 KB Output is correct
4 Correct 33 ms 13256 KB Output is correct
5 Correct 32 ms 13364 KB Output is correct
6 Correct 25 ms 9920 KB Output is correct
7 Correct 30 ms 11324 KB Output is correct
8 Incorrect 4 ms 768 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 27320 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -