#include <bits/stdc++.h>
using namespace std;
#define ll 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
vector<int>pp(6);
void pre(){
pp[0] = 1;
for(int i =1;i<=5;++i)pp[i] = pp[i-1]*28;
}
int conv(const string &s){
int res = 0;
for(int i = 0;i<s.size();++i){
int val = s[i]-'a'+2;
if(s[i]=='?')val = 1;
res+=val*pp[i];
}
return res;
}
int give(char &x){
int val = x-'a'+2;
if(x=='?')val = 1;
return val;
}
void solve()
{
int n,m;
cin >> n >> m;
int u = (1ll<<m);
map<int,int>cnt[(1ll<<m)];
ll res = 0;
for(int i = 1;i<=n;++i){
string s;
cin >> s;
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){
int v = 0,con = 0;
for(int k = 0;k<w;++k){
if(j&(1ll<<k))con+=(give(s[pos[k]])*pp[k]);
else con+=pp[k];
v+=(1ll<<pos[k]);
}
res+=cnt[v][con];
}
for(int j = 0;j<(1ll<<m);++j){
int con = 0,p = 0;
for(int k = 0;k<m;++k){
if(j&(1ll<<k))con+=(give(s[k])*pp[p++]);
}
cnt[j][con]++;
}
}
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;
pre();
for(int i = 1;i<=T;++i)
{
// cout << "Case #" << i << ": ";
solve();
}
}
Compilation message
parametriziran.cpp: In function 'int conv(const string&)':
parametriziran.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 0;i<s.size();++i){
| ~^~~~~~~~~
parametriziran.cpp: In function 'void solve()':
parametriziran.cpp:62:9: warning: unused variable 'u' [-Wunused-variable]
62 | int u = (1ll<<m);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
360 KB |
Output is correct |
2 |
Correct |
17 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
920 KB |
Output is correct |
2 |
Correct |
23 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
692 KB |
Output is correct |
2 |
Correct |
49 ms |
1780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
7096 KB |
Output is correct |
2 |
Correct |
36 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
432 ms |
17576 KB |
Output is correct |
2 |
Correct |
59 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
800 ms |
33248 KB |
Output is correct |
2 |
Correct |
351 ms |
15064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1429 ms |
60160 KB |
Output is correct |
2 |
Correct |
136 ms |
3488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1241 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |