93pts求调,Wa#11
查看原帖
93pts求调,Wa#11
1263684
Elysialr楼主2025/1/20 15:59
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353
#define SIZE 10001

ll n,m,r,c,p1,p2;
string s1[SIZE],s2[SIZE];

ll kmp(string s){
    ll Next[SIZE];
    ll l=s.size();
    s=' '+s;
    Next[1]=0;
    for(ll i=2,j=0;i<=l;i++){
        while(j>0&&s[i]!=s[j+1]) j=Next[j];
        if(s[i]==s[j+1]) j++;
        Next[i]=j;
    }
    return l-Next[l];
}
ll lca(ll x,ll y){
    return x*y/__gcd(x,y);
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    cin>>n>>m;
    for(ll i=1;i<=n;i++){
        cin>>s1[i];
        for(ll j=1;j<=m;j++)
        s2[j]+=s1[i][j-1];
    }

    p1=1,p2=1;
    for(ll i=1;i<=n;i++)
    p1=lca(p1,kmp(s1[i]));
    for(ll i=1;i<=m;i++)
    p2=lca(p2,kmp(s2[i]));
    cout<<min(p1,m)*min(p2,n);

	return 0;
}
2025/1/20 15:59
加载中...