QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#277282 | #5066. String-dle Count | zhaohaikun | TL | 0ms | 0kb | C++14 | 2.5kb | 2023-12-06 17:21:47 | 2023-12-06 17:21:47 |
answer
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T& x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const int MOD = 1e9 + 7;
inline void add(int &x, ll y) {x = (x + y) % MOD;}
int n, m, f[1 << 19], t1[30], t2[30], cnt[30], e[30], lim[30], g[20][1 << 19], gg[20][1 << 19];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m;
int full = (1 << m) - 1;
ms(e, -1);
while (n--) {
string a, b; cin >> a >> b;
a = ' ' + a, b = ' ' + b;
ms(cnt, 0);
F(j, 1, m) {
int id = a[j] - 'A' + 1;
if (b[j] == 'O') {
if (cnt[id] == -1) return puts("0"), 0;
cnt[id]++;
t1[id] |= 1 << (j - 1);
} else {
if (b[j] == 'x') {
if (~cnt[id]) {
if ((~e[id]) && e[id] != cnt[id]) return puts("0"), 0;
e[id] = cnt[id];
cnt[id] = -1;
}
} else {
if (cnt[id] == -1) return puts("0"), 0;
cnt[id]++;
}
t2[id] |= 1 << (j - 1);
}
}
F(j, 1, 26) chkmax(lim[j], cnt[j]);
}
// debug << "OK\n";
int ss = 0;
F(i, 1, 26) {
if ((~e[i]) && e[i] < lim[i]) return puts("0"), 0;
if (~e[i]) lim[i] = e[i];
ss += lim[i];
}
if (ss > m) return puts("0"), 0;
f[0] = 1;
F(i, 1, 26) {
if (t1[i] & t2[i]) return puts("0"), 0;
ms(g, 0);
swap(f, g[0]);
F(j, 1, m) {
ms(gg, 0);
F(t, 0, min(j - 1, lim[i])) {
F(l, 0, full) {
if (!(t1[i] & (1 << (j - 1)))) add(gg[t][l], g[t][l]);
if (!(t2[i] & (1 << (j - 1))) && !(l & (1 << (j - 1)))) {
if (t == lim[i]) {
if (e[i] == -1) add(gg[t][l | (1 << (j - 1))], g[t][l]);
} else {
add(gg[t + 1][l | (1 << (j - 1))], g[t][l]);
}
}
}
}
swap(g, gg);
}
swap(f, g[lim[i]]);
// debug << lim[i] << " " << e[i] << " " << t1[i] << " " << t2[i] << endl;
// F(l, 0, full)
// if (f[l]) cout << i << " " << l << " " << f[l] << endl;
}
cout << f[full];
return 0;
}
/* why?
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 5 CRANE xx--x NASAL OOxOO