//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
#define mt make_tuple
#define mp make_pair
template <typename T1, typename T2>
bool umax(T1 &a, const T2&b) { return a < b ? a = b, 1 : 0;}
template <typename T1, typename T2>
bool umin(T1 &a, const T2 &b) {return a > b ? a = b, 1 : 0;}
template <typename T>
T sqr(T a) {return a * a;}
mt19937 rng(20010709);
const int mod = 1000000007;
const int INF = 1000000001;
const int N = 50005;
map <string, int> used;
vector <string> str[64];
int n, m;
ll result = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
int M = 1 << m;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int mask = 0;
for (int j = 0; j < m; j++)
mask |= (s[j] != '?') << j;
str[mask].push_back(s);
}
auto process = [&](int a, int b) {
used.clear();
for (auto it : str[a]) {
string cur = "";
for (int i = 0; i < m; i++) {
if (((a >> i) & 1) && ((b >> i) & 1))
cur += it[i];
}
used[cur]++;
}
for (auto it : str[b]) {
string cur = "";
for (int i = 0; i < m; i++) {
if (((a >> i) & 1) && ((b >> i) & 1))
cur += it[i];
}
result += used[cur];
}
};
for (int i = 0; i < M; i++) {
for (int j = 0; j < M; j++)
process(i, j);
}
cout << (result - n) / 2 << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1652 KB |
Output is correct |
2 |
Correct |
17 ms |
1584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1736 KB |
Output is correct |
2 |
Correct |
32 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
2164 KB |
Output is correct |
2 |
Correct |
33 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
2480 KB |
Output is correct |
2 |
Correct |
81 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
4200 KB |
Output is correct |
2 |
Correct |
77 ms |
1976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
386 ms |
2496 KB |
Output is correct |
2 |
Correct |
102 ms |
1648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
651 ms |
3848 KB |
Output is correct |
2 |
Correct |
330 ms |
2540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1043 ms |
2780 KB |
Output is correct |
2 |
Correct |
231 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1847 ms |
3520 KB |
Output is correct |
2 |
Correct |
821 ms |
2800 KB |
Output is correct |