#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(c) c.begin(), c.end()
#define endl "\n"
const double PI=3.141592653589;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
void solve()
{
int n,m;
cin >> n >> m;
int u = (1ll<<m);
vector<map<string,int>>cnt(u+1);
int res = 0;
for(int i = 1;i<=n;++i){
string s;
cin >> s;
string get;
vector<int>pos;
for(int j = 0;j<m;++j){
if(s[j]!='?')pos.pb(j);
}
int w = pos.size();
for(int j = 0;j<(1ll<<w);++j){
get.clear();
int v = 0;
for(int k = 0;k<w;++k){
if(j&(1ll<<k))get+=s[pos[k]];
else get+='?';
v+=(1ll<<pos[k]);
}
res+=cnt[v][get];
}
if(w==0)res+=(i-1);
get.clear();
for(int j = 1;j<(1ll<<m);++j){
get.clear();
for(int k = 0;k<m;++k){
if(j&(1ll<<k)){
get+=s[k];
}
}
cnt[j][get]++;
}
}
cout << res << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int T=1;
for(int i = 1;i<=T;++i)
{
// cout << "Case #" << i << ": ";
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
468 KB |
Output is correct |
2 |
Correct |
14 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
468 KB |
Output is correct |
2 |
Correct |
34 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
1648 KB |
Output is correct |
2 |
Correct |
31 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
1308 KB |
Output is correct |
2 |
Correct |
75 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
379 ms |
11960 KB |
Output is correct |
2 |
Correct |
85 ms |
1464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
713 ms |
29560 KB |
Output is correct |
2 |
Correct |
105 ms |
2760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1321 ms |
55344 KB |
Output is correct |
2 |
Correct |
583 ms |
25072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1048 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
935 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |