1 条题解

  • 1
    @ 2023-7-5 14:22:35

    image

    #include <bits/stdc++.h>
    using namespace std;
    const int N=100005;
    string s;
    int n,m,k,t,l,a[N],tot,ans,tmp,b[N];
    //a[i]:编号为i的字符串出现次数 
    map<string,int> mp;
    int main()
    { 
        cin>>n;
        for (int i=1;i<=n;++i){
    		cin>>s;
    		mp[s]=i;
    	}
    	cin>>m;l=1;
    	for (int r=1;r<=m;++r){
    		cin>>s;
    		if (mp.find(s)!=mp.end()){
    			b[r]=mp[s];//b[i] 表示文章中第i个单词的编号 
    			if (++a[b[r]]==1) ++tot;
    			while (b[l]==0 || a[b[l]]>1){
    				--a[b[l]];
    				++l;
    			}	
    			if (tot>ans || (tot==ans && r-l+1<tmp)){
    				ans=tot;
    				tmp=r-l+1;
    			}
    		}
    	}
    	cout<<ans<<"\n"<<tmp;
    }
    
    • 1

    信息

    ID
    240
    时间
    1000ms
    内存
    125MiB
    难度
    1
    标签
    递交数
    61
    已通过
    41
    上传者