QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269333 | #7623. Coloring Tape | FISHER_ | WA | 1ms | 6048kb | C++14 | 2.0kb | 2023-11-29 15:25:12 | 2023-11-29 15:25:13 |
Judging History
answer
#include <bits/stdc++.h>
#define PB push_back
#define EB emplace_back
using namespace std;
const int mod = 998244353;
inline int Mod(int x) { return x + ((x >> 31) & mod); }
inline int add(int x, int y) { return Mod(x + y - mod); }
inline int sub(int x, int y) { return Mod(x - y); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline void upd(int& x, int y) { x = add(x, y); }
const int maxn = 14, maxm = 500, M = 120000;
struct op { int x, y, df; };
vector<op> L[maxm + 5];
int fr[M], to[M], col[M][maxn + 5];
int p[maxn + 5];
bool vis[maxn + 5];
int f[2][1 << maxn];
inline bool get(int v, int w) { return (v >> w) & 1; }
int main() {
int n, m, r;
scanf("%d%d%d", &n, &m, &r);
for (int i = 1; i <= r; i++) {
int c, x, y, df;
scanf("%d%d%d%d", &c, &x, &y, &df);
if (c == 1 && !df) return puts("0"), 0;
L[c].PB({x, y, df});
}
int S = 1 << n;
int tc = 0;
for (int s = 0; s < S; s++) {
int c = 0;
for (int i = 0; i < n; i++)
if (get(s, i)) p[++c] = i;
for (int s2 = s; s2 < S; s2 = (s2 + 1) | s) {
memset(vis, 0, sizeof(vis));
int ns = S - 1;
for (int i = 0; i < n; i++)
if (!get(s, i)) {
int t = i - 1;
if (get(s2, i)) t += 2;
if (t < 0 || t >= n || vis[t] || vis[t + 1]) goto ed;
vis[t] = 1, ns ^= 1 << t;
}
fr[++tc] = s, to[tc] = ns;
for (int i = 1, j = 0; i <= c; i++, j++) {
while (vis[j]) j++;
for (int k = p[i]; k <= j; k++) col[tc][k] = i;
}
ed:;
}
}
int nw = 0, lt = 1;
f[nw][S - 1] = 1;
for (int i = 2; i <= m; i++) {
swap(nw, lt);
memset(f[nw], 0, sizeof(f[nw]));
for (int w = 1; w < S; w <<= 1)
for (int j = 0; j < S; j += (w << 1))
for (int k = 0; k < w; k++) upd(f[lt][j + k], f[lt][w + j + k]);
for (int j = 1; j <= tc; j++) {
bool flg = 1;
for (const auto& [x, y, df] : L[i])
if ((col[j][x - 1] != col[j][y - 1]) != df) { flg = 0; break; }
if (flg) upd(f[nw][to[j]], f[lt][fr[j]]);
}
}
int ans = 0;
for (int s = 1; s < S; s++) upd(ans, f[nw][s]);
printf("%d", ans);
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6048kb
input:
3 5 3 3 2 3 0 4 1 2 0 5 1 3 0
output:
19
result:
ok 1 number(s): "19"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4020kb
input:
5 10 10 9 3 4 1 2 4 5 0 7 2 3 0 9 2 3 0 6 3 5 0 6 2 4 1 2 4 5 0 1 1 3 1 7 2 4 0 10 2 3 0
output:
1370
result:
wrong answer 1st numbers differ - expected: '1514', found: '1370'