1 solutions

  • 0
    @ 2025-1-11 16:44:22
    #include<bits/stdc++.h>
    using namespace std;
    typedef string str;
    const int b=7,mod=5005;
    int cnt=0;
    vector<str>hx[5010];
    int h(str x){
    	int len=x.length(),ans=0;
    	for( int i=0;i<len;i++){
    		ans=ans*b%mod+x[i]%mod;
    	//	cout<<ans<<' ';
    	}
    	return ans%mod;
    }
    void search(str x){
    	if(hx[h(x)].size()==0){
    		hx[h(x)].push_back(x);
    		cnt++;
    	}
    	else{
    		for(int i=0;i<hx[h(x)].size();i++){
    			if(hx[h(x)][i]==x){
    				return;
    			}
    		}
    		hx[h(x)].push_back(x);
    		cnt++;
    	}
    }
    int main(){
    	//cout<<h("CD");
    	int n;
    	scanf("%d",&n);
    	for(int i=0;i<n;i++){
    		str a;
    		cin>>a;
    		search(a);
    	}
    	printf("%d",cnt);
    	return 0;
    }
    
    • 1

    Information

    ID
    312
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    9
    Tags
    # Submissions
    55
    Accepted
    5
    Uploaded By