Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define debug(a) cout<<a<<endl
- #define pii pair<int,int>
- #define maxn 10009
- using namespace std;
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(0);
- set<string> prefixs;
- set<string> suffixs;
- prefixs.insert("");
- suffixs.insert("");
- int n;
- cin>>n;
- string ans="";
- for(int i=0;i<n;i++){
- string s;
- cin>>s;
- if(i!=0 && ans==""){
- for(int j=0;j<10;j++){
- if(suffixs.find(s.substr(0,j+1))!=suffixs.end() && prefixs.find(s.substr(j+1,10))!=prefixs.end()){
- ans=s;
- }
- }
- }
- for(int j=0;j<10;j++){
- prefixs.insert(s.substr(0,j+1));
- suffixs.insert(s.substr(10-j-1,10));
- }
- }
- if(ans=="")cout<<"ok"<<'\n';
- else cout<<ans<<'\n';
- return 0;
- }
- ///usar double sempre ou long double
- ///N esquecer de limpar as coisas em quest de varios testes
- ///OLHAR A COMPLEXIDADE PRA VER SE N PASSA POR BRUTE FORCE OU BRUTE FORCE COM ALGUMAS OTIMIZACOES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement