#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int M = 6;
const int AL = 27;
multiset<ll> cnt[(1<<M)][(1<<M)];
ll pwr[M];
int main(){
fastIO;
int n, m;
cin >> n >> m;
pwr[0]=1;
for(int i = 1; i <= m ; i ++ ){
pwr[i]=(pwr[i-1]*1ll*AL);
}
string s;
int res;
ll clc;
ll soln = 0;
for(int i = 1; i <= n; i ++ ){
cin >> s;
int que = 0;
for(int j = 0; j < m ; j ++ ){
if(s[j] == '?') que |= (1 << j);
}
for(int q2 = 0 ; q2 < (1 << m) ; q2 ++ ){
res = (que | q2);
clc = 0;
for(int j = 0 ; j < m ; j ++ ){
if((res & (1 << j))) continue;
clc += pwr[j] * 1ll * (s[j] - 'a' + 1);
}
soln += cnt[q2][res].count(clc);
}
for(int sum = 0; sum < (1 << m); sum ++ ){
if((sum & que) != que) continue;
clc = 0;
for(int j = 0 ; j < m ; j ++ ){
if((sum & (1 << j))) continue;
clc += pwr[j] * 1ll * (s[j] - 'a' + 1);
}
cnt[que][sum].insert(clc);
}
}
cout << soln << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1259 ms |
5324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
731 ms |
5304 KB |
Output is correct |
2 |
Correct |
2673 ms |
3916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3057 ms |
5204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
463 ms |
9068 KB |
Output is correct |
2 |
Execution timed out |
3044 ms |
5040 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3098 ms |
7556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1061 ms |
28908 KB |
Output is correct |
2 |
Execution timed out |
3029 ms |
3200 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1277 ms |
27792 KB |
Output is correct |
2 |
Execution timed out |
3083 ms |
3172 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1336 ms |
50796 KB |
Output is correct |
2 |
Execution timed out |
3047 ms |
9748 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1449 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1843 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |