-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path1262-Password.cpp
46 lines (43 loc) · 993 Bytes
/
1262-Password.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
#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
bool dfs(string& cur,vector<set<char>>& cols,const int& k){
int idx = cur.length();
if(idx == 5){
if(++cnt == k){
cout << cur << endl;
return true;
}
return false;
}
for(auto& c : cols[idx]){
cur += c;
if(dfs(cur,cols,k)) return true;
cur.pop_back();
}
return false;
}
int main()
{
int t,k;
string in;
cin >> t;
while(t--){
cin >> k;
vector<unordered_set<char>> temp(5);
vector<set<char>> cols(5);
cnt = 0;
for(int l=0;l<2;l++)
for(int i=0;i<6;i++){
cin >> in;
for(int j=0;j<5;j++){
if(l==0) temp[j].insert(in[j]);
else if(temp[j].count(in[j])){
cols[j].insert(in[j]);
}
}
}
string cur = "";
if(!dfs(cur,cols,k)) cout << "NO" << endl;
}
}