#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 64;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
map <int,int> cnt[M][M];
int n, m;
ll ans;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
string s;
cin >> s;
int mask = 0, tmp[M];
fill(tmp, tmp+64, -1);
for(int j = 0; j < m; ++j) if(s[j] != '?') mask |= (1 << j);
for(int mask2 = 0; mask2 < (1 << m); ++mask2){
if((mask & mask2) != mask2) continue;
int cur = 0;
for(int j = 0, p = 1; j < m; ++j, p *= 26) if((mask2 >> j) & 1) cur += p * (s[j] - 'a');
tmp[mask2] = cur;
}
for(int mask2 = 0; mask2 < (1 << m); ++mask2){
int res = (mask & mask2);
ans += cnt[mask2][res][tmp[res]];
}
for(int mask2 = 0; mask2 < (1 << m); ++mask2) if(tmp[mask2] != -1) ++cnt[mask][mask2][tmp[mask2]];
}
cout << ans << endl;
return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
460 KB |
Output is correct |
2 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
460 KB |
Output is correct |
2 |
Correct |
12 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1176 KB |
Output is correct |
2 |
Correct |
13 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
1100 KB |
Output is correct |
2 |
Correct |
32 ms |
1956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
7340 KB |
Output is correct |
2 |
Correct |
21 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
420 ms |
17940 KB |
Output is correct |
2 |
Correct |
23 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
791 ms |
33220 KB |
Output is correct |
2 |
Correct |
317 ms |
15120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1436 ms |
60060 KB |
Output is correct |
2 |
Correct |
42 ms |
3396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1272 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |