This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 <= i ; ++j){
sol += processmaskpair(i, j);
}
}
sol -= n;
cout << sol << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |