QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#461939 | #5066. String-dle Count | alpha1022 | WA | 1ms | 6136kb | C++14 | 2.6kb | 2024-07-03 10:47:41 | 2024-07-03 10:47:41 |
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], ++cnt[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]);
if (i == 14) printf("%d %d\n", cnt[i], vis[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]);
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6136kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
0 0 0 0 21
result:
wrong answer 1st numbers differ - expected: '21', found: '0'