#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<int> cnt[(1<<M)][(1<<M)];
int 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]*AL;
}
string s;
int res;
int 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1183 ms |
5228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
700 ms |
5392 KB |
Output is correct |
2 |
Correct |
2649 ms |
3948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3040 ms |
5364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
452 ms |
8956 KB |
Output is correct |
2 |
Execution timed out |
3044 ms |
4844 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3086 ms |
7664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1018 ms |
28524 KB |
Output is correct |
2 |
Execution timed out |
3046 ms |
3308 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1237 ms |
27628 KB |
Output is correct |
2 |
Execution timed out |
3079 ms |
3308 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1318 ms |
50340 KB |
Output is correct |
2 |
Execution timed out |
3074 ms |
9792 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1455 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1831 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |