#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ft first
#define sd second
#define sz(x) ((int)x.size())
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const int N = 50100;
const ll Z = 28;
gp_hash_table<int, int> mem;
string s[N];
int n, m;
ll ans = 0;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> s[i];
for (int msk = 0; msk < (1 << m); msk++){
bool bad = 0;
int t = 0;
for (int j = 0; j < m && !bad; j++)
if (msk & (1 << j)) {
if (s[i][j] == '?')
bad = 1;
else t = t * Z + 26;
} else {
if (s[i][j] == '?')
t = t * Z + 27;
else t = t * Z + (s[i][j] - 'a');
}
if (!bad)
mem[t]++;
}
}
for (int i = 0; i < n; i++){
for (int msk = 0; msk < (1 << m); msk++){
int t = 0;
for (int j = 0; j < m; j++)
if (msk & (1 << j)) {
if (s[i][j] == '?')
t = t * Z + 26;
else t = t * Z + 27;
} else {
if (s[i][j] == '?')
t = t * Z + 27;
else t = t * Z + (s[i][j] - 'a');
}
if (mem.find(t) != mem.end())
ans += mem[t];
}
}
cout << (ans - n) / 2;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1920 KB |
Output is correct |
2 |
Correct |
10 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1920 KB |
Output is correct |
2 |
Correct |
13 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2624 KB |
Output is correct |
2 |
Correct |
29 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2624 KB |
Output is correct |
2 |
Correct |
83 ms |
3196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
365 ms |
6632 KB |
Output is correct |
2 |
Correct |
35 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
11328 KB |
Output is correct |
2 |
Correct |
37 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
20568 KB |
Output is correct |
2 |
Correct |
101 ms |
11368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
39048 KB |
Output is correct |
2 |
Correct |
94 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
498 ms |
38956 KB |
Output is correct |
2 |
Correct |
414 ms |
20444 KB |
Output is correct |