Submission #593518

# Submission time Handle Problem Language Result Execution time Memory
593518 2022-07-11T10:14:05 Z BlueShark_14 Palindromes (APIO14_palindrome) C++14
100 / 100
57 ms 69140 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>


using namespace __gnu_pbds;
using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

//#define mx                     200005
#define INF_mx                 1e18
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

/*
const ll sz=1000001;
const ll N=1e12;
vector<ll>prime;
bool flag[sz+3];


void sieve(void)
{
    ll i,j,add;
    flag[0]=flag[1]=1;
    prime.push_back(2);
    for(i=4; i<sz; i+=2)
        flag[i]=1;
    for(i=3; i<sz; i+=2)
    {
        if(!flag[i])
        {
            prime.push_back(i);
            if(sz/i>=i)
            {
                add=i*2;
                for(j=i*i; j<sz; j+=add)
                    flag[j]=1;
            }
        }

    }
}
*/
/*
const int MOD = 1000000007 ;
long long int  bigmod ( long long B, int P, int M )
{
    if ( P == 0 )return 1;
    if ( P % 2 ) {
        return ( ( B % M ) * ( bigmod ( B, P-1, M))) % M;
    }
    else {
        long long mod = bigmod (B,P/2,M);
        return ((mod%M)*(mod%M))%M;
    }
}

*/

/*
 tree<
       int,
     null_type,
     less_equal<int>,
     rb_tree_tag,
     tree_order_statistics_node_update>t;

*/

const ll N  = 3e5 + 10 ;

ll Tree[N][26], idx;
ll len[N], link[N], t;
string s;

ll occ[N];

void pre_set(){
      len[1] = -1, link[1] = 1;
      len[2] = 0, link[2] = 1;
      idx = t = 2 ;
      mem(occ, 0);
}
void extend(int p)
{
   while(s[p - len[t] - 1 ] !=  s[p]) t = link[t];

   int x = link[t];
   while(s[p - len[x] -1] != s[p] ) x = link[x];

   int c = s[p] - 'a';

   if(!Tree[t][c]){
     Tree[t][c] =  ++idx;
     len[idx] = len[t]+2;
     link[idx] = len[idx] == 1 ? 2 : Tree[x][c];
   }
   t = Tree[t][c];
   occ[t]++;
}



int main()
{

 fast_in_out

     cin>>s;

     pre_set();

     for(int i=0; i<s.size(); i++){
        extend(i);
     }
     for(int i=idx; i>2 ;i--){
        occ[link[i]]+=occ[i];
     }

     ll mx=0;
     for(int i=idx; i>2; i--){
        if(occ[i]*len[i] > mx ) mx = occ[i] * len[i];
     }

     cout << mx << endl;
    return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:134:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |      for(int i=0; i<s.size(); i++){
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2640 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2632 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 1 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2900 KB Output is correct
2 Correct 2 ms 2900 KB Output is correct
3 Correct 2 ms 2900 KB Output is correct
4 Correct 1 ms 2900 KB Output is correct
5 Correct 2 ms 2900 KB Output is correct
6 Correct 2 ms 2900 KB Output is correct
7 Correct 2 ms 2900 KB Output is correct
8 Correct 2 ms 2900 KB Output is correct
9 Correct 2 ms 2768 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4820 KB Output is correct
2 Correct 2 ms 4820 KB Output is correct
3 Correct 2 ms 4820 KB Output is correct
4 Correct 2 ms 4820 KB Output is correct
5 Correct 2 ms 4824 KB Output is correct
6 Correct 3 ms 4820 KB Output is correct
7 Correct 2 ms 4824 KB Output is correct
8 Correct 2 ms 2780 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 3 ms 4184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 24756 KB Output is correct
2 Correct 14 ms 24816 KB Output is correct
3 Correct 14 ms 24804 KB Output is correct
4 Correct 15 ms 24748 KB Output is correct
5 Correct 17 ms 24816 KB Output is correct
6 Correct 12 ms 18772 KB Output is correct
7 Correct 13 ms 21336 KB Output is correct
8 Correct 3 ms 3028 KB Output is correct
9 Correct 7 ms 7892 KB Output is correct
10 Correct 14 ms 21440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 68732 KB Output is correct
2 Correct 42 ms 69140 KB Output is correct
3 Correct 40 ms 69056 KB Output is correct
4 Correct 39 ms 69092 KB Output is correct
5 Correct 57 ms 69088 KB Output is correct
6 Correct 37 ms 61728 KB Output is correct
7 Correct 36 ms 57984 KB Output is correct
8 Correct 6 ms 3688 KB Output is correct
9 Correct 6 ms 3688 KB Output is correct
10 Correct 54 ms 57184 KB Output is correct
11 Correct 44 ms 69072 KB Output is correct
12 Correct 9 ms 9564 KB Output is correct