#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;
const int Z = 28;
string s[N], t;
int n, m;
ll ans = 0;
struct trie{
trie* next[Z];
int kol;
trie(): kol(0) {
fill(next, next + Z, nullptr);
}
void insert(string &cur, int id){
kol++;
if (id == m) return;
int ch = 0;
if (cur[id] == '#')
ch = 26;
else if (cur[id] == '?')
ch = 27;
else ch = (cur[id] - 'a');
// cerr << next[ch] << '\n';
if (!next[ch])
next[ch] = new trie();
next[ch] -> insert(cur, id + 1);
}
void calc(string &cur, int id){
if (id == m){
ans += kol;
return;
}
if (cur[id] == '?'){
if (next[26]) next[26] -> calc(cur, id + 1);
next[27] -> calc(cur, id + 1);
} else {
next[cur[id] - 'a'] -> calc(cur, id + 1);
if (next[27]) next[27] -> calc(cur, id + 1);
}
}
};
trie* root;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m;
root = new trie();
for (int i = 0; i < n; i++){
cin >> s[i];
for (int msk = 0; msk < (1 << m); msk++){
bool bad = 0;
t = "";
for (int j = 0; j < m && !bad; j++)
if (msk & (1 << j)) {
if (s[i][j] == '?')
bad = 1;
else t += "#";
} else t += s[i][j];
if (!bad)
root -> insert(t, 0);
}
}
for (int i = 0; i < n; i++)
root -> calc(s[i], 0);
cout << (ans - n) / 2;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
4096 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
3968 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
25 ms |
11008 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
9208 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
132 ms |
62072 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
163 ms |
65544 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
126 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
104 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
98 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |