-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1703d_double_strings.cpp
67 lines (54 loc) · 1.47 KB
/
1703d_double_strings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Universidade de Brasília
* Departamento de Ciência da Computação
* CIC0169 - Programação Competitiva
* Prof. Dr. Vinicius R. P. Borges
*
* Tópico: Estruturas de Dados
* Aula: Resolucao do problema
* Codeforces Round #806 (Div. 4) - D. Double Strings (https://mirror.codeforces.com/contest/1703/problem/D)
*
* POR FAVOR: nao submeter esse código-fonte diretamente no Codeforces
*
* Compilar no terminal: g++ 1703d_double_strings.cpp -std=c++17 -o doubles
* Executar: ./doubles
*/
#include<bits/stdc++.h>
using namespace std;
int solve(string s, set<string> hash[9]){
for(int j = 1; j <= s.size(); j++){
int other = s.size()-j;
string subs = s.substr(0,j);
if(hash[j].count(subs)){
string subs2 = s.substr(j,other);
if(hash[other].count(subs2)){
return 1;
}
}
}
return 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
set<string> hash[9];
vector<string> input;
for(int i = 0; i < n; i++){
string s;
cin >> s;
int ind = s.size();
hash[ind].insert(s);
input.push_back(s);
}
string s = "";
for(int i = 0; i < input.size(); i++){
s+=to_string(solve(input[i],hash));
}
cout << s << "\n";
}
return 0;
}