QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#281979 | #5066. String-dle Count | SampsonYW | TL | 1ms | 3888kb | C++14 | 2.2kb | 2023-12-11 09:02:51 | 2023-12-11 09:02:52 |
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, m, mus[N], ban[N];
int cnt[M], lim[M];
int L[M], R[M];
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]);
}
// for(re int i = 0; i < M; ++i)
// cout << char(i + 'A') << " = " << L[i] << ", " << R[i] << "\n";
// for(re int i = 0; i < n; ++i)
// if(~mus[i]) cout << i << " must = " << char(mus[i] + 'A') << "\n";
map<vector<int>, int> dp;
dp[vector<int>(M, 0)] = 1;
for(re int i = 0; i < n; ++i) {
map<vector<int>, int> ndp; swap(dp, ndp);
for(auto it : ndp) {
auto v = it.fi; int w = it.se, need = 0;
for(re int c = 0; c < M; ++c) need += L[c] - v[c];
for(re int c = 0; c < M; ++c) {
if(~mus[i] && c != mus[i]) continue;
if(v[c] == R[c]) continue;
if(ban[i] >> c & 1) continue;
// cout << "trans " << i << " " << char(c + 'A') << "\n";
int las = v[c], nxt = v[c] + 1;
if(R[c] > n) nxt = min(nxt, L[c]);
if(need - (L[c] - las) + (L[c] - nxt) >= n - i) continue;
v[c] = nxt, addr(dp[v], w), v[c] = las;
}
}
}
int ans = 0;
for(auto it : dp) {
auto v = it.fi; int w = it.se; bool F = 1;
for(re int c = 0; c < M; ++c) {
if(v[c] < L[c]) F = 0;
if(R[c] <= n && v[c] < R[c]) F = 0;
}
if(F) addr(ans, w);
}
cout << ans;
cerr << 1.0 * clock() / CLOCKS_PER_SEC;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3764kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3824kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3888kb
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...