QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277287 | #5066. String-dle Count | zhaohaikun | TL | 767ms | 87820kb | C++14 | 2.8kb | 2023-12-06 17:25:19 | 2023-12-06 17:25:19 |
Judging History
answer
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
// 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, lim[i]))
F(l, 0, full)
gg[t][l] = 0;
F(t, 0, min(j - 1, lim[i])) {
F(l, 0, full) if (g[t][l]) {
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]);
}
}
}
}
F(t, 0, min(j, lim[i]))
F(l, 0, full)
g[t][l] = gg[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?
*/
詳細信息
Test #1:
score: 100
Accepted
time: 355ms
memory: 87784kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5688kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 258ms
memory: 87600kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 767ms
memory: 87820kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 751ms
memory: 87536kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 159ms
memory: 87580kb
input:
1 1 K x
output:
25
result:
ok 1 number(s): "25"
Test #8:
score: -100
Time Limit Exceeded
input:
19 19 ZAZZZAZZZZZZZZZZAAZ x-xxxxxxxxxxxxxxxxx ZBZBZZBZZZZBZZZZBZZ x-xxxxxxxxxxxxxxxxx CZZCZZCZCZZCZZZCZZZ -xxxxxxxxxxxxxxxxxx ZDZZDZDZZZZZZZZZZZZ x-xxxxxxxxxxxxxxxxx ZZZZEEZEZZEEZZZZZZZ xxxx-xxxxxxxxxxxxxx ZZZZZFZZZZZZZZZZZZF xxxxx-xxxxxxxxxxxxx ZZGGZZZZZZZZGGGZZGZ xx-xxxxxxxxxxxxxxxx HHHHZHZZZZHHZZ...