QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#281994 | #5066. String-dle Count | SampsonYW | TL | 705ms | 6812kb | C++14 | 2.1kb | 2023-12-11 09:20:24 | 2023-12-11 09:20:25 |
Judging History
answer
#include <bits/stdc++.h>
#define il inline
#define re register
#define ll long long
#define ull unsigned ll
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
using namespace std;
#define N 19
#define M 26
#define P 1000000007
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
int n, mus[N], ban[N];
int cnt[M], lim[M];
int L[M], R[M];
int m, v[N], mask[M];
int now, cur = 1, dp[2][1 << N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T; cin >> T >> n;
memset(mus, -1, sizeof(mus));
memset(R, 0x3f, sizeof(R));
while(T--) {
string A, B; cin >> A >> B;
memset(cnt, 0, sizeof(cnt));
memset(lim, 0x3f, sizeof(lim));
for(re int i = 0; i < n; ++i) {
int c = A[i] - 'A', v = B[i];
if(v == 'x') lim[c] = cnt[c], ban[i] |= 1 << c;
if(v == '-') ++cnt[c], ban[i] |= 1 << c;
if(v == 'O') mus[i] = c, ++cnt[c];
}
for(re int i = 0; i < M; ++i)
L[i] = max(L[i], cnt[i]), R[i] = min(R[i], lim[i]);
}
int least = 0;
for(re int i = 0; i < M; ++i) {
least += L[i]; if(L[i] > R[i]) {cout << 0; return 0;}
}
if(least > n) {cout << 0; return 0;}
for(re int i = 0; i < M; ++i)
for(re int j = 0; j < L[i]; ++j)
mask[i] |= 1 << m, v[m++] = i;
dp[0][0] = 1;
for(re int i = 0; i < n; ++i) {
swap(now, cur), memset(dp[now], 0, sizeof(now));
for(re int S = 0; S < 1 << m; ++S) {
int w = dp[cur][S];
for(re int c = 0; c < m; ++c) {
if(S >> c & 1) continue;
if(c && v[c] == v[c - 1] && !(S >> (c - 1) & 1)) continue;
if(~mus[i] && v[c] != mus[i]) continue;
if(ban[i] >> v[c] & 1) continue;
addr(dp[now][S | (1 << c)], w);
}
for(re int c = 0; c < M; ++c) {
if((S & mask[c]) != mask[c]) continue;
if(~mus[i] && c != mus[i]) continue;
if((ban[i] >> c & 1) || R[c] <= n) continue;
addr(dp[now][S], w);
}
}
}
cout << dp[now][(1 << m) - 1];
cerr << 1.0 * clock() / CLOCKS_PER_SEC;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5788kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5920kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5924kb
input:
1 1 K x
output:
25
result:
ok 1 number(s): "25"
Test #8:
score: 0
Accepted
time: 705ms
memory: 6812kb
input:
19 19 ZAZZZAZZZZZZZZZZAAZ x-xxxxxxxxxxxxxxxxx ZBZBZZBZZZZBZZZZBZZ x-xxxxxxxxxxxxxxxxx CZZCZZCZCZZCZZZCZZZ -xxxxxxxxxxxxxxxxxx ZDZZDZDZZZZZZZZZZZZ x-xxxxxxxxxxxxxxxxx ZZZZEEZEZZEEZZZZZZZ xxxx-xxxxxxxxxxxxxx ZZZZZFZZZZZZZZZZZZF xxxxx-xxxxxxxxxxxxx ZZGGZZZZZZZZGGGZZGZ xx-xxxxxxxxxxxxxxxx HHHHZHZZZZHHZZ...
output:
182644947
result:
ok 1 number(s): "182644947"
Test #9:
score: -100
Time Limit Exceeded
input:
19 19 AZZZZZAZZZZZZAZZZZZ -xxxxxxxxxxxxxxxxxx ZZZBZZBBZZBBZZBZBZB xxx-xxxxxxxxxxxxxxx ZZZZZCCZZZZZZZZZZZZ xxxxx-xxxxxxxxxxxxx ZZZDZDZZZZZZDZZZZDZ xxx-xxxxxxxxxxxxxxx EZZZZZZZEZZZZZZZZZZ -xxxxxxxxxxxxxxxxxx ZZZZZZZZFFZZZZZZZZZ xxxxxxxx-xxxxxxxxxx ZZZZZZZZZZZZZGZZZZG xxxxxxxxxxxxx-xxxxx ZZHHZZHZZZHZZH...