• RT,最后输出 最长公共前缀的长度*最长公共前缀串的个数
  • //#include<bits/stdc++.h>
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<set>
    #include<vector>
    #include<map>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<fstream>
    #include<algorithm>
    using namespace std;
    
    #define rep(i,a,n) for(int i=a;i<=n;i++)
    #define per(i,a,n) for(int i=n;i>=a;i--)
    //#define CLR(a) memset(a,sizeof(a),0)
    
    typedef long long ll;
    typedef unsigned long long ull;
    
    const int INF = 0x3f3f3f3f;
    
    const int maxn = 4e5+10; 
    int trie[maxn][2],tot=1;
    int en[maxn];
    char s[maxn];
    int ans;
    void insert(char *str){
        int len = strlen(str), p=1;
        for(int k=0;k<len;k++){
            int ch=str[k]-'0';
            if(trie[p][ch]==0)trie[p][ch]=++tot;
            p=trie[p][ch];
            ++en[p];
            ans=max(ans,(k+1)*en[p]);
        }
        //end[p]=true;
    }
    //bool search(char *str){
    //    int len=strlen(str),p=1;
    //    for(int i=0;i<len;i++){
    //        int ch=str[i]-'a';
    //        if(trie[p][ch]==0)return false;
    //        p=trie[p][ch];
    //    }
    //    return end[p];
    //}
    int main(){
    	int t;
    	scanf("%d", &t);
    	while(t--){
    		memset(en,0,sizeof(en));
    		memset(trie,0,sizeof(trie));
    		
    		ans = 0;
    		tot=1;
    		int n;
    		scanf("%d", &n);
    		rep(i,1,n){
    			scanf("%s", s);
    			insert(s);
    		}
    		printf("%d\n", ans);
    	}
    }

发表评论

邮箱地址不会被公开。 必填项已用*标注