QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292543 | #5066. String-dle Count | _LAP_ | WA | 373ms | 39348kb | C++14 | 2.5kb | 2023-12-28 07:50:07 | 2023-12-28 07:50:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 20, MOD = 1e9 + 7;
inline int Plus(int a, int b) {return a + b >= MOD ? a + b - MOD : a + b; }
inline int Minus(int a, int b) {return a - b < 0 ? a - b + MOD : a - b; }
inline int ksm(long long a, int b) {
long long r = 1;
for(; b; b >>= 1, a = a * a % MOD)
if(b & 1) r = r * a % MOD;
return r;
}
int n, ban[N], L[26], R[26];
int f[N][1 << N];
inline int solve() {
int T; cin >> T >> n;
for(int i = 0; i < 26; i ++) L[i] = 0, R[i] = n;
while(T --) {
string A, B; cin >> A >> B;
vector<int> siz(26, 0);
for(int i = 0; i < n; i ++) if(B[i] == 'O') {
siz[A[i] - 'c'] ++;
ban[i] |= ((1 << 26) - 1) ^ (1 << A[i] - 'A');
}
for(int i = 0; i < n; i ++) if(B[i] != 'O') {
if(B[i] == '-') L[A[i] - 'A'] = max(L[A[i] - 'A'], ++siz[A[i] - 'A']);
else R[A[i] - 'A'] = min(R[A[i] - 'A'], siz[A[i] - 'A']);
ban[i] |= 1 << (A[i] - 'A');
}
for(int i = 0; i < 26; i ++) L[i] = max(L[i], siz[i]);
}
for(int i = 0; i < 26; i ++)
if(L[i] > R[i]) return 0;
int least = 0;
for(int i = 0; i < 26; i ++)
least += L[i];
if(least > n) return 0;
static int in[N], trans[1 << N];
for(int i = 0, tot = 0; i < 26; i ++) {
for(int j = 0; j < L[i]; j ++)
in[tot ++] = i;
}
memset(trans, 0, sizeof trans);
for(int mask = 0; mask < (1 << least); mask ++) {
for(int i = 0, tot = 0; i < 26; i ++) {
int siz = 0;
for(int j = 0; j < L[i]; j ++)
siz += (mask >> tot & 1), tot ++;
if(siz == L[i] && L[i] < R[i]) trans[mask] |= 1 << i;
}
}
f[0][0] = 1;
for(int i = 1; i <= n; i ++) {
for(int mask = 0; mask < (1 << least); mask ++) if(f[i - 1][mask]) {
for(int j = 0; j < least; j ++) if(!(mask >> j & 1)) {
int ch = in[j]; if(ban[i - 1] >> ch & 1) continue;
f[i][mask | (1 << j)] = Plus(f[i][mask | (1 << j)], f[i - 1][mask]);
}
int T = trans[mask]; T = T ^ (T & ban[i - 1]);
f[i][mask] = Plus(f[i][mask], 1ll * f[i - 1][mask] * __builtin_popcount(T) % MOD);
}
}
return f[n][(1 << least) - 1];
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int T = 1;// cin >> T;
while(T --)
cout << solve() << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7552kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3432kb
input:
1 5 BBBAA xxxx-
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
2 5 ABCDE -xxxx ABCDE xxxxx
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 7660kb
input:
1 3 ABC ---
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 7660kb
input:
1 15 AAAAAAAAAAAAAAB -xxxxxxxxxxxxxx
output:
918547951
result:
ok 1 number(s): "918547951"
Test #6:
score: 0
Accepted
time: 0ms
memory: 7700kb
input:
1 15 AAAAAAAAAAAAAAA -xxxxxxxxxxxxxx
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 2ms
memory: 7572kb
input:
1 1 K x
output:
25
result:
ok 1 number(s): "25"
Test #8:
score: 0
Accepted
time: 194ms
memory: 23944kb
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: 362ms
memory: 39204kb
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: 361ms
memory: 39296kb
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: 358ms
memory: 39284kb
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: 373ms
memory: 36640kb
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: 351ms
memory: 39008kb
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: 3492kb
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: 371ms
memory: 39348kb
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: 2ms
memory: 7612kb
input:
1 3 PYP xxx
output:
13824
result:
ok 1 number(s): "13824"
Test #17:
score: 0
Accepted
time: 0ms
memory: 7536kb
input:
3 3 ENP xxx PJK xxx BZL xxx
output:
5832
result:
ok 1 number(s): "5832"
Test #18:
score: 0
Accepted
time: 2ms
memory: 7616kb
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: 0ms
memory: 7580kb
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: 7544kb
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'