1 条题解

  • 1
    @ 2021-8-7 21:01:05

    C++ :

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    const int maxn=10006;
    char c[maxn][80];
    int nex[maxn];
    bool use[80];
    int n,m;
    void getNext(){
        int k=-1,j=0;
        nex[0]=-1;
        while(j<n)
        if(k==-1||strcmp(c[j],c[k])==0){
            nex[++j]=++k;
        }else
            k=nex[k];
    }
    int main(){
        cin>>n>>m;
        memset(use,true,sizeof use);
        for(int i=0;i<n;i++){
            scanf("%s",c[i]);
            for(int j=1;j<=m;j++){
                if(use[j]){
                    for(int k=j;k<m;k++){
                        if(c[i][k]!=c[i][k-j]){
                            use[j]=false;
                            break;
                        }
                    }
                }
            }
        }
        int width;
        for(int i=1;i<=m;i++){
            if(use[i]){
                width=i;
                break;
            }
        }
        getNext();
        int height=n-nex[n];
        cout<<width*height<<endl;
        return 0;
    }
    
    • 1

    信息

    ID
    70
    时间
    1000ms
    内存
    128MiB
    难度
    1
    标签
    递交数
    45
    已通过
    40
    上传者