QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461937 | #5066. String-dle Count | alpha1022 | WA | 736ms | 265880kb | C++14 | 2.5kb | 2024-07-03 10:41:27 | 2024-07-03 10:41:28 |
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; }
int sum = accumulate(cl, cl + S, 0);
if (sum > m) { puts("0"); return 0; }
if (sum == m)
for (int i = 0; i < S; ++i) cr[i] = cl[i];
f[0][0][0][0] = 1;
for (int c = 0; c < S; ++c) {
if (!cr[c]) {
for (int s = 0; s < 1 << m; ++s)
f[~c & 1][0][0][s] = exchange(f[c & 1][0][0][s], 0);
continue;
}
for (int i = 0; i < m; ++i)
for (int j = 0; j <= cl[c] + 1 && j <= cr[c]; ++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 <= cr[c]; ++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]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4008kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 2ms
memory: 16092kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 36ms
memory: 20360kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 25ms
memory: 14344kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
1 1 K x
output:
25
result:
ok 1 number(s): "25"
Test #8:
score: 0
Accepted
time: 736ms
memory: 257532kb
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: 574ms
memory: 259952kb
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: 569ms
memory: 250900kb
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: 565ms
memory: 265880kb
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: 567ms
memory: 259104kb
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: 555ms
memory: 250280kb
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: 3756kb
input:
26 19 AAAAAAAAAAAAAAAAAAA ------------------- BBBBBBBBBBBBBBBBBBB ------------------- CCCCCCCCCCCCCCCCCCC ------------------- DDDDDDDDDDDDDDDDDDD ------------------- EEEEEEEEEEEEEEEEEEE ------------------- FFFFFFFFFFFFFFFFFFF ------------------- GGGGGGGGGGGGGGGGGGG ------------------- HHHHHHHHHHHHHH...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 568ms
memory: 256348kb
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...
output:
143269517
result:
ok 1 number(s): "143269517"
Test #16:
score: 0
Accepted
time: 1ms
memory: 4008kb
input:
1 3 PYP xxx
output:
13824
result:
ok 1 number(s): "13824"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
3 3 ENP xxx PJK xxx BZL xxx
output:
5832
result:
ok 1 number(s): "5832"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
5 3 LLK xxx WUQ xxx RDR xxx EUZ xxx FBU xxx
output:
3375
result:
ok 1 number(s): "3375"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3952kb
input:
10 3 PKX xxx FBB xxx JSZ xxx RGB xxx BOS x-x OPG Oxx SHW xxx RDM xxx LHO xx- NBP xxx
output:
81
result:
ok 1 number(s): "81"
Test #20:
score: -100
Wrong Answer
time: 0ms
memory: 3832kb
input:
15 3 DCJ xxx NCW xxx WDE xxx MAO xOO JXC xxx OBO xxO ALB -xx JWZ xxx QXK xxx FZW xxx VAJ xOx VHL xxx AZG -x- BWQ xxx GWB Oxx
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'