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>
#define ft first
#define sd second
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 50100;
unordered_map<string, int> mem[(1 << 6)];
string s[N], t;
int n, m, kol[(1 << 6)];
ll ans = 0;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> s[i];
for (int msk = 1; msk < (1 << m); msk++){
t = "";
bool bad = 0;
for (int j = 0; j < m && !bad; j++)
if (msk & (1 << j)) {
if (s[i][j] == '?')
bad = 1;
else t += s[i][j];
}
if (!bad) {
mem[msk][t]++;
kol[msk]++;
}
}
}
for (int i = 0; i < n; i++){
int cur = n - 1;
for (int msk = 1; msk < (1 << m); msk++){
t = "";
bool bad = 0;
for (int j = 0; j < m && !bad; j++)
if (msk & (1 << j)) {
if (s[i][j] == '?')
bad = 1;
else t += s[i][j];
}
if (!bad)
cur += ((kol[msk] - mem[msk][t]) * (__builtin_parity(msk) ? -1 : 1));
}
ans += cur;
}
assert(ans % 2 == 0);
cout << ans / 2;
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... |