QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#461930 | #5066. String-dle Count | alpha1022 | TL | 962ms | 253596kb | C++14 | 2.3kb | 2024-07-03 10:35:03 | 2024-07-03 10:35:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int norm(int x) { return x >= mod ? x - mod : x; }
int reduce(int x) { return x < 0 ? x + mod : x; }
int neg(int x) { return x ? mod - x : 0; }
int quo2(int x) { return (x + (x & 1 ? mod : 0)) >> 1; }
void add(int &x, int y) { x += y, x = x >= mod ? x - mod : x; }
void sub(int &x, int y) { x -= y, x = x < 0 ? x + mod : x; }
void fam(int &x, int y, int z) { x = (x + (ll)y * z) % mod; }
int mpow(int a, int b) {
int ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = (ll)ret * a % mod;
a = (ll)a * a % mod;
}
return ret;
}
const int M = 19;
const int S = 26;
int n, m;
int valid[M];
int cl[S], cr[S];
char s[M + 1], t[M + 1];
int cnt[S]; bool vis[S];
int f[2][M + 1][M + 1][1 << M];
int main() {
scanf("%d%d", &n, &m), fill_n(valid, m, (1 << S) - 1), fill_n(cr, S, m);
for (; n; --n) {
scanf("%s%s", s, t), fill_n(cnt, S, 0), fill_n(vis, S, 0);
for (int i = 0; i < m; ++i) s[i] -= 'A';
for (int i = 0; i < m; ++i)
if (t[i] == 'O') valid[i] &= 1 << s[i];
else {
valid[i] &= ~(1 << s[i]);
if (t[i] == 'x') vis[s[i]] = 1;
else if (vis[s[i]]) { puts("0"); return 0; }
else ++cnt[s[i]];
}
for (int i = 0; i < S; ++i) {
cl[i] = max(cl[i], cnt[i]);
if (vis[i]) cr[i] = min(cr[i], cnt[i]);
}
}
for (int i = 0; i < S; ++i) if (cl[i] > cr[i]) { puts("0"); return 0; }
if (accumulate(cl, cl + S, 0) > m) { puts("0"); return 0; }
f[0][0][0][0] = 1;
for (int c = 0; c < S; ++c) {
for (int i = 0; i < m; ++i)
for (int j = 0; j <= cl[c] + 1 && j <= m; ++j)
for (int s = 0; s < 1 << m; ++s)
if (f[c & 1][i][j][s]) {
add(f[c & 1][i + 1][j][s], f[c & 1][i][j][s]);
if ((~s >> i & 1) && (valid[i] >> c & 1))
add(f[c & 1][i + 1][min(j, cl[c]) + 1][s ^ (1 << i)], f[c & 1][i][j][s]);
}
for (int i = 0; i <= (cr[c] == m) && cl[c] + i <= m; ++i)
for (int s = 0; s < 1 << m; ++s)
add(f[~c & 1][0][0][s], f[c & 1][m][cl[c] + i][s]);
for (int i = 0; i <= m; ++i)
for (int j = 0; j <= cl[c] + 1 && j <= m; ++j) fill_n(f[c & 1][i][j], 1 << m, 0);
}
printf("%d\n", f[S & 1][0][0][(1 << m) - 1]);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4060kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 35ms
memory: 16416kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 31ms
memory: 16360kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
1 1 K x
output:
25
result:
ok 1 number(s): "25"
Test #8:
score: 0
Accepted
time: 951ms
memory: 249676kb
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: 0
Accepted
time: 962ms
memory: 249784kb
input:
19 19 AZZZZZAZZZZZZAZZZZZ -xxxxxxxxxxxxxxxxxx ZZZBZZBBZZBBZZBZBZB xxx-xxxxxxxxxxxxxxx ZZZZZCCZZZZZZZZZZZZ xxxxx-xxxxxxxxxxxxx ZZZDZDZZZZZZDZZZZDZ xxx-xxxxxxxxxxxxxxx EZZZZZZZEZZZZZZZZZZ -xxxxxxxxxxxxxxxxxx ZZZZZZZZFFZZZZZZZZZ xxxxxxxx-xxxxxxxxxx ZZZZZZZZZZZZZGZZZZG xxxxxxxxxxxxx-xxxxx ZZHHZZHZZZHZZH...
output:
791604390
result:
ok 1 number(s): "791604390"
Test #10:
score: 0
Accepted
time: 956ms
memory: 251900kb
input:
19 19 ZAZAZZZZAZZZZZZAZZZ x-xxxxxxxxxxxxxxxxx ZBZZZBZZBZZZZZZZBZZ x-xxxxxxxxxxxxxxxxx ZZZZZZZCZCZZZZZZZZZ xxxxxxx-xxxxxxxxxxx ZDDDZZZDZZZZZZZZZZZ x-xxxxxxxxxxxxxxxxx ZEZZEEZZZZZEZZEZZZE x-xxxxxxxxxxxxxxxxx ZZZFZZZZFZZZZZFZFFZ xxx-xxxxxxxxxxxxxxx ZZZGGZZZZZZZZZZZZZG xxx-xxxxxxxxxxxxxxx ZHHZZZZZZZZZHZ...
output:
721023482
result:
ok 1 number(s): "721023482"
Test #11:
score: 0
Accepted
time: 929ms
memory: 249788kb
input:
19 19 ZZZAZZZAZZZAZZAAZZA xxx-xxxxxxxxxxxxxxx BBZZBZZBZZZBBBZZBZB -xxxxxxxxxxxxxxxxxx ZZCZCCZCCCZCCZCCZZC xx-xxxxxxxxxxxxxxxx ZDZZDZDDZDZZZDZDDZZ x-xxxxxxxxxxxxxxxxx EEZEZEZEZZZZEZEEEZE -xxxxxxxxxxxxxxxxxx ZZZFZFFFZFFFFZFFFFZ xxx-xxxxxxxxxxxxxxx ZGZGGZGZGZGGGZZGGGZ x-xxxxxxxxxxxxxxxxx ZHZZZHZHHZZHZZ...
output:
432987142
result:
ok 1 number(s): "432987142"
Test #12:
score: 0
Accepted
time: 933ms
memory: 250652kb
input:
19 19 ZAAZAZZAAZAZZZZZZAA x-xxxxxxxxxxxxxxxxx ZBZBBBZZBZZBZBBBZZB x-xxxxxxxxxxxxxxxxx CZCCCZZCCCZZZCCZZCC -xxxxxxxxxxxxxxxxxx DZDZDDDDZDDZZZZZZDD -xxxxxxxxxxxxxxxxxx ZEEEEEZZEEZEZZZZEZE x-xxxxxxxxxxxxxxxxx ZZFFZZZFZFFFZZFFZFF xx-xxxxxxxxxxxxxxxx ZZGZZZGZGZZGZZZGZGG xx-xxxxxxxxxxxxxxxx HZZZHZHZZZZZHZ...
output:
562846236
result:
ok 1 number(s): "562846236"
Test #13:
score: 0
Accepted
time: 945ms
memory: 253596kb
input:
19 19 AZZZZAZAZZZAZAZZAZZ -xxxxxxxxxxxxxxxxxx BZBBZBZZZBBZBZBBZBZ -xxxxxxxxxxxxxxxxxx ZCCCCCZCCZCCZZCZZCC x-xxxxxxxxxxxxxxxxx DDDDZDDZDZDZDDDZZDZ -xxxxxxxxxxxxxxxxxx EZZEZZEZZEEZEEZZEEZ -xxxxxxxxxxxxxxxxxx ZZZZFZZFZZZFZZZZFZZ xxxx-xxxxxxxxxxxxxx GGZGZGGZGGZGGZZZGGG -xxxxxxxxxxxxxxxxxx ZHZZHHHHHZZHHH...
output:
241578701
result:
ok 1 number(s): "241578701"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
26 19 AAAAAAAAAAAAAAAAAAA ------------------- BBBBBBBBBBBBBBBBBBB ------------------- CCCCCCCCCCCCCCCCCCC ------------------- DDDDDDDDDDDDDDDDDDD ------------------- EEEEEEEEEEEEEEEEEEE ------------------- FFFFFFFFFFFFFFFFFFF ------------------- GGGGGGGGGGGGGGGGGGG ------------------- HHHHHHHHHHHHHH...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: -100
Time Limit Exceeded
input:
19 19 ZAZZZZZZZZZZZZZZZZZ x-xxxxxxxxxxxxxxxxx ZZZZZZZZBZZZZZZZZZZ xxxxxxxx-xxxxxxxxxx ZZZZZZZZZZZZZZCZZZZ xxxxxxxxxxxxxx-xxxx ZZDZZZZZZZZZZZZZZZZ xx-xxxxxxxxxxxxxxxx ZZZZZZZZZZZZZEZZZZZ xxxxxxxxxxxxx-xxxxx ZZZZZZZZZZZZZZZFZZZ xxxxxxxxxxxxxxx-xxx ZZZZZZZZZZZGZZZZZZZ xxxxxxxxxxx-xxxxxxx ZZZZZZZZZZZZZZ...