#include <bits/stdc++.h>
#define ft first
#define sd second
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 50100;
const int Z = 28;
unordered_map<string, int> mem;
string s[N], t;
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;
t = "";
for (int j = 0; j < m && !bad; j++)
if (msk & (1 << j)) {
if (s[i][j] == '?')
bad = 1;
else t += "#";
} else t += s[i][j];
if (!bad)
mem[t]++;
}
}
for (int i = 0; i < n; i++){
for (int msk = 0; msk < (1 << m); msk++){
t = "";
for (int j = 0; j < m; j++)
if (msk & (1 << j)) {
if (s[i][j] == '?')
t += "#";
else t += "?";
} else t += s[i][j];
if (mem.find(t) != mem.end())
ans += mem[t];
}
}
cout << (ans - n) / 2;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1920 KB |
Output is correct |
2 |
Correct |
21 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
2048 KB |
Output is correct |
2 |
Correct |
32 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
3072 KB |
Output is correct |
2 |
Correct |
41 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
2680 KB |
Output is correct |
2 |
Correct |
77 ms |
3576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
9352 KB |
Output is correct |
2 |
Correct |
90 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
506 ms |
16056 KB |
Output is correct |
2 |
Correct |
164 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
858 ms |
28376 KB |
Output is correct |
2 |
Correct |
489 ms |
14008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1397 ms |
45904 KB |
Output is correct |
2 |
Correct |
327 ms |
2352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2305 ms |
65216 KB |
Output is correct |
2 |
Correct |
1508 ms |
32920 KB |
Output is correct |