This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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;
}
# | 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... |