Created
May 5, 2018 14:54
-
-
Save limzunyuan/ca93c4c08c24348e689da727bdc9be8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma GCC optimize("Ofast,no-stack-protector") | |
#pragma GCC target("avx,tune=native") | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int ll; | |
typedef pair<ll, ll> pii; | |
template<typename T> | |
using pq_gt = priority_queue<T, vector<T>, greater<T>>; | |
template<typename T> | |
using pq_lt = priority_queue<T, vector<T>, less<T>>; | |
#define se second | |
#define fi first | |
#define pb push_back | |
string grid[2020]; | |
string s; | |
map<string, int> m; | |
string ans; | |
vector<set<char>>v; | |
bool solve(int a, int b, int c) { | |
//cout<<s<<endl; | |
if(c==b) { | |
//cout<<m[s]<<endl; | |
if(m[s]==0) { | |
ans = s; | |
return true; | |
} | |
//cout<<"false"<<endl; | |
return false; | |
} | |
for(char ch:v[c]) { | |
//cout<<i<<" "<<a<<endl; | |
s += ch; | |
if(solve(a,b,c+1)) { | |
return true; | |
} | |
s.pop_back(); | |
} | |
return false; | |
} | |
int main() { | |
ios::sync_with_stdio(false); | |
int t; | |
cin>>t; | |
for(int tt = 1; tt<=t; tt++) { | |
cout<<"Case #"<<tt<<": "; | |
int a,b; | |
m.clear(); | |
cin>>a>>b; | |
s = ""; | |
v.clear(); | |
v.resize(b); | |
for(int i = 0; i < a; ++i) { | |
cin>>grid[i]; | |
m[grid[i]]++; | |
for(int j = 0; j < b; ++j) { | |
v[j].insert(grid[i][j]); | |
} | |
} | |
if(solve(a,b, 0)) { | |
cout<<ans<<endl; | |
} else { | |
cout<<"-"<<endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment