#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
int n, m;
string s[50005];
vector <string> a[(1 << 7) + 5];
ll sol;
ll processmaskpair(int x, int y){
map <string, ll> c;
for(vector <string>::iterator i = a[x].begin() ; i != a[x].end() ; ++i){
string o = *i;
string t = "";
for(int j = 0 ; j < m ; ++j){
if((x & (1 << j)) && (y & (1 << j))){
t += o[j];
}
}
c[t]++;
}
ll ret = 0;
for(vector <string>::iterator i = a[y].begin() ; i != a[y].end() ; ++i){
string o = *i;
string t = "";
for(int j = 0 ; j < m ; ++j){
if((x & (1 << j)) && (y & (1 << j))){
t += o[j];
}
}
ret += c[t];
}
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0 ; i < n ; ++i){
cin >> s[i];
}
for(int i = 0 ; i < n ; ++i){
int mask = 0;
for(int j = 0 ; j < m ; ++j){
if(s[i][j] != '?'){
mask |= (1 << j);
}
}
a[mask].push_back(s[i]);
}
for(int i = 0 ; i < (1 << m) ; ++i){
for(int j = 0 ; j < (1 << m) ; ++j){
sol += processmaskpair(i, j);
}
}
sol -= n;
sol /= 2;
cout << sol << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3180 KB |
Output is correct |
2 |
Correct |
35 ms |
3204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
3296 KB |
Output is correct |
2 |
Correct |
32 ms |
4720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
3700 KB |
Output is correct |
2 |
Correct |
34 ms |
3128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
4016 KB |
Output is correct |
2 |
Correct |
63 ms |
3044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
5640 KB |
Output is correct |
2 |
Correct |
70 ms |
3504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
379 ms |
3940 KB |
Output is correct |
2 |
Correct |
102 ms |
3304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
587 ms |
5412 KB |
Output is correct |
2 |
Correct |
308 ms |
4256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
954 ms |
4336 KB |
Output is correct |
2 |
Correct |
229 ms |
3304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1474 ms |
5120 KB |
Output is correct |
2 |
Correct |
777 ms |
4336 KB |
Output is correct |