1 条题解

  • 2
    @ 2025-4-28 11:58:40

    哈希+枚举

    • 第一层枚举长度,第二层从1枚举到n,map存哈希值

    • 如果当前长度下,没有字符串有公共前缀,那就break,因为后面的长度都不可能有了

    bool M1;
    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ull unsigned long long
    #define deb(x) cerr<<"l: "<<__LINE__<<"  "<<#x<<"="<<x<<'\n'
    #define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<"MB\n"
    
    namespace syr
    {
    	const ll N = 1e6+10;
    	const ll V = 1e7+10;
    	const ull M = 13;
    	char c;
    	ll n, ax, ans;
    	ll len[N], v[V];
    	ull t[N];
    	unordered_map <ull, ll> m;
    	string s[N];
    	void work()
    	{
    		cin>>n;
    		c = getchar();
    		for (ll i=1; i<=n; i++) {
    			s[i] = " ";
    			while (c=getchar()) {
    				if (c=='\n') break;
    				s[i] += c;
    				len[i]++;
    			}
    			ax = max(ax, len[i]);
    		}
    		ans = ax;
    		for (ll i=1; i<=ax; i++) {
    			m.clear();
    			for (ll j=1; j<=n; j++) {
    				if (len[j]<i) continue;
    				t[j] = t[j]*M + s[j][i]-'a'+1;
    				m[t[j]]++;
    				v[i] = max(v[i], m[t[j]]);
    			}
    			if (v[i]==1) break;
    			ans = max(ans, i*v[i]); 
    		}
    		cout<<ans<<'\n';
    	}
    }
    
    bool M2;
    
    int main()
    {
    //	cin.tie(0)->sync_with_stdio(0);
    	look_memory;
    	syr::work();
    	return 0;
    }
    
    • 1

    信息

    ID
    187
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    (无)
    递交数
    100
    已通过
    3
    上传者