Submission #6593400


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
char laz[maxn];
int pi[12*maxn],m,n;
string buf;
int prefix_function(const string &s,const string &t) {
    ///search t on s
    m=(int)t.length();
    n =(int)t.length()+(int)s.length()+1;
    buf=t+'#'+s;
    pi[0]=0;
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && buf[i] != buf[j])
            j = pi[j-1];
        if (buf[i] == buf[j])
            j++;
        pi[i] = j;
    }
    int ma=-1;
    for(int i=n-1;i>m;i--){
        pi[i]=(pi[i]==m?1:0);
        if(i+m<n&&pi[i]==1){
            pi[i]+=pi[i+m];
        }
        ma=max(ma,pi[i]);
    }
    return ma;
}
string s,t,a,ss,tt;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>ss>>t;
    s=ss;
    while((int)s.length()<=(int)t.length()+(int)ss.length()){
        s+=ss;
    }
    s+=ss;
    int c=prefix_function(s,t);
    if(c==-1){
       return cout<<"0",0;
    }
    s+=s;
    int cc=prefix_function(s,t);
    if(cc==c){
        return cout<<cc,0;
    }
    else{
        return cout<<-1,0;
    }
}
/*
    Good Luck
        -Lci70121
*/

Submission Info

Submission Time
Task F - Strings of Eternity
User Lucina
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1201 Byte
Status AC
Exec Time 65 ms
Memory 30512 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 70
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51, b52, b53, b54, b55, b56, b57, b58, b59, b60, b61, b62, b63, b64, b65, b66, b67, b68, b69, b70
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 1 ms 256 KB
b10 AC 1 ms 256 KB
b11 AC 1 ms 256 KB
b12 AC 65 ms 30384 KB
b13 AC 65 ms 30512 KB
b14 AC 50 ms 22460 KB
b15 AC 25 ms 9820 KB
b16 AC 45 ms 18980 KB
b17 AC 48 ms 22460 KB
b18 AC 63 ms 30256 KB
b19 AC 45 ms 18980 KB
b20 AC 41 ms 22460 KB
b21 AC 64 ms 28976 KB
b22 AC 46 ms 29176 KB
b23 AC 55 ms 28976 KB
b24 AC 38 ms 18980 KB
b25 AC 43 ms 22460 KB
b26 AC 39 ms 18980 KB
b27 AC 52 ms 30384 KB
b28 AC 52 ms 29464 KB
b29 AC 50 ms 30256 KB
b30 AC 50 ms 28720 KB
b31 AC 48 ms 29080 KB
b32 AC 46 ms 28720 KB
b33 AC 47 ms 30128 KB
b34 AC 37 ms 22460 KB
b35 AC 47 ms 30128 KB
b36 AC 34 ms 21680 KB
b37 AC 40 ms 22460 KB
b38 AC 40 ms 22460 KB
b39 AC 48 ms 29844 KB
b40 AC 39 ms 22588 KB
b41 AC 39 ms 22460 KB
b42 AC 47 ms 29852 KB
b43 AC 49 ms 28976 KB
b44 AC 39 ms 22460 KB
b45 AC 49 ms 29636 KB
b46 AC 49 ms 29488 KB
b47 AC 41 ms 22460 KB
b48 AC 37 ms 21680 KB
b49 AC 38 ms 22460 KB
b50 AC 48 ms 28848 KB
b51 AC 50 ms 28976 KB
b52 AC 38 ms 22460 KB
b53 AC 49 ms 30512 KB
b54 AC 37 ms 22460 KB
b55 AC 38 ms 22460 KB
b56 AC 32 ms 18980 KB
b57 AC 31 ms 18988 KB
b58 AC 9 ms 5740 KB
b59 AC 2 ms 512 KB
b60 AC 11 ms 6292 KB
b61 AC 4 ms 1692 KB
b62 AC 5 ms 2808 KB
b63 AC 31 ms 18980 KB
b64 AC 38 ms 22460 KB
b65 AC 39 ms 22460 KB
b66 AC 46 ms 28848 KB
b67 AC 48 ms 29608 KB
b68 AC 37 ms 22460 KB
b69 AC 37 ms 22460 KB
b70 AC 47 ms 28464 KB