#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<ll, 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;
ll 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++){
ll 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2048 KB |
Output is correct |
2 |
Correct |
9 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
2048 KB |
Output is correct |
2 |
Correct |
12 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3196 KB |
Output is correct |
2 |
Correct |
26 ms |
2624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3196 KB |
Output is correct |
2 |
Correct |
86 ms |
4344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
359 ms |
11236 KB |
Output is correct |
2 |
Correct |
36 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
20460 KB |
Output is correct |
2 |
Correct |
34 ms |
2624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
39000 KB |
Output is correct |
2 |
Correct |
125 ms |
20448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
163 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
158 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |