标签:carp ack pac out hone int name main space
思路:用map做的话,只能出现一次循环,否则会超时。
代码:
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define mp make_pair map<string,int> ma; string ans[70005]; int main(){ int n; string s,nu; cin>>n; for(int i=0;i<n;i++){ cin>>s; ans[i+1] = ""; for(int j=0;j<9;j++){ nu = ""; for(int k=j;k<9;k++){ nu += s[k]; if(ma[nu] && ma[nu]!=i+1) ma[nu]=-1; else ma[nu] = i+1; } } } for(auto it : ma){ if(it.s!=-1) if(ans[it.s]=="" || ans[it.s].size()>it.f.size() ) ans[it.s] = it.f; } for(int i=1;i<=n;i++) cout<<ans[i]<<endl; return 0; }
Codeforces 861D - Polycarp's phone book
标签:carp ack pac out hone int name main space
原文地址:http://www.cnblogs.com/widsom/p/7569471.html