#include <bits/stdc++.h>
using namespace std;
typedef tuple<char,char,char,char,char,char> sexta;
map<sexta, int> dicio;
long long total;
string original;
int M, N;
inline sexta set_pos(sexta s, int pos, char c){
if(pos == 0){
return make_tuple(c, get<1>(s), get<2>(s), get<3>(s), get<4>(s), get<5>(s));
}
else if(pos == 1){
return make_tuple(get<0>(s), c, get<2>(s), get<3>(s), get<4>(s), get<5>(s));
}
else if(pos == 2){
return make_tuple(get<0>(s), get<1>(s), c, get<3>(s), get<4>(s), get<5>(s));
}
else if(pos == 3){
return make_tuple(get<0>(s), get<1>(s), get<2>(s), c, get<4>(s), get<5>(s));
}
else if(pos == 4){
return make_tuple(get<0>(s), get<1>(s), get<2>(s), get<3>(s), c, get<5>(s));
}
else if(pos == 5){
return make_tuple(get<0>(s), get<1>(s), get<2>(s), get<3>(s), get<4>(s), c);
}
return s;
}
void brute_insert(int pos, sexta davez){
if(pos == M){
//cout << "Original: " << original << " Davez: " << davez << endl;
dicio[davez]++;
return;
}
if(original[pos] != '?'){
brute_insert(pos+1, set_pos(davez, pos, original[pos]));
brute_insert(pos+1, set_pos(davez, pos, '?'));
}
else{
brute_insert(pos+1, set_pos(davez, pos, '!'));
}
}
void brute_count(int pos, sexta davez){
if(pos == M){
//cout << "Original: " << original << " Davez: " << davez << endl;
if(dicio.count(davez)) total += dicio[davez];
return;
}
brute_count(pos+1, set_pos(davez, pos, original[pos]));
brute_count(pos+1, set_pos(davez, pos, '!'));
}
int main(){
sexta vazia = make_tuple('0', '0', '0', '0', '0', '0');
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
cin >> N >> M;
for(int i = 0; i < N; i++){
cin >> original;
brute_count(0, vazia);
brute_insert(0, vazia);
}
cout << total << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
632 KB |
Output is correct |
2 |
Correct |
17 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
504 KB |
Output is correct |
2 |
Correct |
38 ms |
572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
1324 KB |
Output is correct |
2 |
Correct |
56 ms |
776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
1296 KB |
Output is correct |
2 |
Correct |
119 ms |
1856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
417 ms |
7124 KB |
Output is correct |
2 |
Correct |
104 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
623 ms |
12992 KB |
Output is correct |
2 |
Correct |
132 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
797 ms |
23644 KB |
Output is correct |
2 |
Correct |
668 ms |
11000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1166 ms |
37468 KB |
Output is correct |
2 |
Correct |
240 ms |
908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1892 ms |
56884 KB |
Output is correct |
2 |
Correct |
1565 ms |
28236 KB |
Output is correct |