This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |