-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_Numeric_String_Template.cpp
More file actions
79 lines (52 loc) · 1.66 KB
/
C_Numeric_String_Template.cpp
File metadata and controls
79 lines (52 loc) · 1.66 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
# include <iostream>
# define ll long long
#include <bits/stdc++.h>
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std ;
unsigned ll dist(ll x ,ll y , ll x1 , ll y1 ){
unsigned ll ditx = (x1 -x)*(x1 -x);
unsigned ll dity = ( y1 - y)*( y1 - y);
unsigned ll ans = ditx + dity;
return ans;
}
int main (){
FAST
ll t; cin >> t; while (t--){
ll n ; cin >> n; ll arr[n];
for(ll i = 0 ;i < n;i++){
cin >> arr[i];
}
ll q ; cin >> q;
while(q--){
string ss ; cin >> ss;
ll fl = 1;
if(ss.size() == n){
map<ll,char> pp;
for(ll i =0 ;i < n;i++){
if(pp.find(arr[i]) == pp.end()){
pp[arr[i]] = ss[i];
}else if (pp[arr[i]] != ss[i]) {
fl = 0;
}
}
map<char,ll> dd;
for(ll i =0 ;i < n;i++){
if(dd.find(ss[i]) == dd.end()){
dd[ss[i]] = arr[i];
}else if (dd[ss[i]] != arr[i]) {
fl = 0;
}
}
for(auto& x: dd){
if(x.first != pp[x.second]) fl = 0;
}
}else {
fl = 0;
}
if(fl) cout << "YES\n" ; else cout << "NO\n";
}
}
}