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 <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
map<string, int> cnt;
vector<string> a(n);
for(int i = 0; i < n; i++) {
string str;
cin >> str;
a[i] = str;
for(int mask = 0; mask < (1 << m); mask++) {
string s = str;
for(int j = 0; j < m; j++) {
if (mask & (1 << j)) {
s[j] = '*';
}
}
cnt[s]++;
}
}
ll ans = 0;
for(string str : a) {
vector<int> idx;
for(int i = 0; i < m; i++) {
if (isalpha(str[i])) {
idx.push_back(i);
}
}
int letters = idx.size();
string str2 = str;
for(char& c : str2) {
if (c == '?') {
c = '*';
}
}
for(int mask = 0; mask < (1 << letters); mask++) {
string s = str2;
for(int j = 0; j < letters; j++) {
if (mask & (1 << j)) {
s[idx[j]] = '?';
}
}
// cout << s << " ";
// cout << cnt[s] << "\n";
ans += cnt[s];
}
// cerr << "\n";
}
ans -= n;
ans /= 2;
cout << ans << "\n";
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... |