//#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;
unordered_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 |
17 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
1652 KB |
Output is correct |
2 |
Correct |
18 ms |
1712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1772 KB |
Output is correct |
2 |
Correct |
30 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
2036 KB |
Output is correct |
2 |
Correct |
30 ms |
1756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
2604 KB |
Output is correct |
2 |
Correct |
42 ms |
1472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
3912 KB |
Output is correct |
2 |
Correct |
97 ms |
2232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
201 ms |
2332 KB |
Output is correct |
2 |
Correct |
92 ms |
1776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
309 ms |
3696 KB |
Output is correct |
2 |
Correct |
230 ms |
2912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
547 ms |
2672 KB |
Output is correct |
2 |
Correct |
198 ms |
1916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
762 ms |
3384 KB |
Output is correct |
2 |
Correct |
436 ms |
2928 KB |
Output is correct |