#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define N 100500
#define oo ll(1e16)
#define ft first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
using namespace std;
typedef long long ll;
typedef long double ld;
int n, m;
ll ans;
string s[N];
vector <int> v[128];
ll f(int x, int y) {
map <string, ll> ma;
ll rs = 0;
for (int i = 0; i < sz(v[x]); i++) {
string t = "";
for (int j = 0; j < m; j++)
if (((1 << j) & x) && ((1 << j) & y))
t += s[v[x][i]][j];
ma[t]++;
}
for (int i = 0; i < sz(v[y]); i++) {
string t = "";
for (int j = 0; j < m; j++)
if (((1 << j) & x) && ((1 << j) & y))
t += s[v[y][i]][j];
rs += ma[t];
}
return rs;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// in("input.txt");
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
int msk = 0;
for (int j = 0; j < m; j++)
if (s[i][j] != '?')
msk |= (1 << j);
v[msk].pb(i);
}
ans = -n;
for (int i = 0; i < (1 << m); i++)
for (int j = 0; j < (1 << m); j++)
ans += f(i, j);
cout << ans / 2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
3840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
3712 KB |
Output is correct |
2 |
Correct |
19 ms |
3712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
3772 KB |
Output is correct |
2 |
Correct |
35 ms |
3840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
4344 KB |
Output is correct |
2 |
Correct |
37 ms |
3712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
4344 KB |
Output is correct |
2 |
Correct |
69 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
245 ms |
5752 KB |
Output is correct |
2 |
Correct |
73 ms |
3840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
395 ms |
4344 KB |
Output is correct |
2 |
Correct |
105 ms |
3712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
621 ms |
5752 KB |
Output is correct |
2 |
Correct |
352 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
999 ms |
4784 KB |
Output is correct |
2 |
Correct |
215 ms |
3712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1559 ms |
5044 KB |
Output is correct |
2 |
Correct |
876 ms |
4344 KB |
Output is correct |