#include <bits/stdc++.h>
using namespace std;
#define long long long
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
class TaskD {
int n, m;
map<int,int> ls[64][64];
long ans;
public:
void solve(istream &cin, ostream &cout) {
cin >> n >> m;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
int h = 0, mask1 = 0;
for(int j = 0; j < m; j++) if(s[j] != '?') mask1 |= 1 << j;
int tmp[64];
fill(tmp, tmp+64, -1);
for(int mask2 = 0; mask2 < 1 << m; mask2++) if((mask2 & mask1) == mask2) {
int h = 0;
for(int j = 0, p = 1; j < m; j++, p *= 26) {
if(mask2 >> j & 1) {
h += p * (s[j] - 'a');
}
}
tmp[mask2] = h;
}
// different mask2
for(int mask2 = 0; mask2 < 1 << m; mask2++) {
int and_mask = mask1 & mask2;
int h = tmp[and_mask];
ans += ls[mask2][and_mask][h];
}
for(int mask2 = 0; mask2 < 1 << m; mask2++) if(tmp[mask2] >= 0) ++ls[mask1][mask2][tmp[mask2]];
}
cout << ans;
}
};
class Solver {
public:
void solve(std::istream& in, std::ostream& out) {
TaskD *obj = new TaskD();
obj->solve(in, out);
delete obj;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solver solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
Compilation message
parametriziran.cpp: In member function 'void TaskD::solve(std::istream&, std::ostream&)':
parametriziran.cpp:19:17: warning: unused variable 'h' [-Wunused-variable]
int h = 0, mask1 = 0;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
652 KB |
Output is correct |
2 |
Correct |
12 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
640 KB |
Output is correct |
2 |
Correct |
21 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1192 KB |
Output is correct |
2 |
Correct |
26 ms |
828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
1120 KB |
Output is correct |
2 |
Correct |
56 ms |
2088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
490 ms |
7536 KB |
Output is correct |
2 |
Correct |
25 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1002 ms |
17916 KB |
Output is correct |
2 |
Correct |
40 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1857 ms |
33468 KB |
Output is correct |
2 |
Correct |
660 ms |
15260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3068 ms |
60020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2631 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |