Submission #6585502


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
char laz[maxn];
int pi[16*maxn];
bool prefix_function(const string &s,const string &t) {
    ///search t on s
    int m=(int)t.length();
    string ss=t+'#'+s;
    int n = (int)ss.length();
    pi[0]=0;
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && ss[i] != ss[j])
            j = pi[j-1];
        if (ss[i] == ss[j])
            j++;
        pi[i] = j;
        if(pi[i]==m&&i>m){
            return true;
        }
    }
    return false;
}
string s,t,a,ss,tt;
/**
There exists a non-negative integer j
such that the concatenation of i copies of t
is a substring of the concatenation of j copies of s.
*/


int main(){
    scanf("%s",laz);
    ss=string(laz);
    scanf("%s",laz);
    t=string(laz);
    s=ss;
    while((int)s.length()<=(int)t.length()+(int)ss.length()){
        s+=ss;
    }
    s+=ss;
    int l=1,r=((int)s.length())/((int)t.length()),mid,c=-1;
    while(l<=r){
        mid=(l+r)>>1;
        a=t;
        for(int i=1;i<mid;i++){
            a+=t;
        }
        if(prefix_function(s,a)){
            c=mid;
            l=mid+1;
        }
        else{
            r=mid-1;
        }
    }
    if(c==-1){
       return !printf("0");
    }
    s+=s;
    l=1,r=((int)s.length())/((int)t.length());
    int cc=-1;
    while(l<=r){
        mid=(l+r)>>1;
        a=t;
        for(int i=1;i<mid;i++){
            a+=t;
        }
        if(prefix_function(s,a)){
            cc=mid;
            l=mid+1;
        }
        else{
            r=mid-1;
        }
    }
    if(cc==c){
        return !printf("%d\n",cc);
    }
    else{
        return !printf("-1");
    }
}
/*
    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 1816 Byte
Status AC
Exec Time 1717 ms
Memory 55484 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:34:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",laz);
                    ^
./Main.cpp:36:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",laz);
                    ^

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 202 ms 55484 KB
b13 AC 135 ms 51360 KB
b14 AC 116 ms 42568 KB
b15 AC 31 ms 14236 KB
b16 AC 1717 ms 42180 KB
b17 AC 92 ms 31844 KB
b18 AC 42 ms 20780 KB
b19 AC 702 ms 31736 KB
b20 AC 78 ms 31460 KB
b21 AC 43 ms 20780 KB
b22 AC 80 ms 40980 KB
b23 AC 121 ms 51360 KB
b24 AC 542 ms 31096 KB
b25 AC 74 ms 31344 KB
b26 AC 454 ms 31224 KB
b27 AC 92 ms 40980 KB
b28 AC 117 ms 51360 KB
b29 AC 110 ms 51360 KB
b30 AC 84 ms 40980 KB
b31 AC 32 ms 20780 KB
b32 AC 31 ms 20780 KB
b33 AC 162 ms 55484 KB
b34 AC 66 ms 31716 KB
b35 AC 83 ms 40980 KB
b36 AC 67 ms 30200 KB
b37 AC 76 ms 31460 KB
b38 AC 71 ms 31344 KB
b39 AC 82 ms 40980 KB
b40 AC 69 ms 31332 KB
b41 AC 71 ms 31344 KB
b42 AC 84 ms 40980 KB
b43 AC 112 ms 51360 KB
b44 AC 71 ms 31332 KB
b45 AC 87 ms 40980 KB
b46 AC 32 ms 20780 KB
b47 AC 95 ms 42312 KB
b48 AC 72 ms 30200 KB
b49 AC 68 ms 31844 KB
b50 AC 32 ms 20780 KB
b51 AC 111 ms 51360 KB
b52 AC 68 ms 31332 KB
b53 AC 81 ms 40980 KB
b54 AC 65 ms 31344 KB
b55 AC 94 ms 40904 KB
b56 AC 241 ms 31096 KB
b57 AC 185 ms 30984 KB
b58 AC 19 ms 6912 KB
b59 AC 1 ms 384 KB
b60 AC 8 ms 5948 KB
b61 AC 7 ms 2312 KB
b62 AC 3 ms 1788 KB
b63 AC 184 ms 30584 KB
b64 AC 68 ms 32100 KB
b65 AC 72 ms 31460 KB
b66 AC 80 ms 40980 KB
b67 AC 81 ms 40980 KB
b68 AC 68 ms 31332 KB
b69 AC 69 ms 32228 KB
b70 AC 84 ms 40980 KB