QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#422310 | #7303. City United | dayux | TL | 0ms | 0kb | C++14 | 1.6kb | 2024-05-27 11:21:29 | 2024-05-27 11:21:29 |
answer
#include <bits/stdc++.h>
const int maxn = 50, maxd = 13, mod = 4;
std::array<int, maxn + 1> e;
std::array<std::array<std::array<int, 1 << maxd>, 1 << maxd>, 2> f;
void inc(int &x, int y) {
if ((x += y) >= mod) {
x -= mod;
}
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
std::cin >> n >> m;
for (int i = 0; i < m; ++i) {
int u, v;
std::cin >> u >> v;
e[std::max(u, v)] |= 1 << (std::abs(u - v) - 1);
}
f[0 & 1][0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int S = 0; S < (1 << maxd); ++S) {
for (int T = S; ; T = (T - 1) & S) {
int R = S ^ T;
f[i & 1][T][R] = 0;
if (T == 0) {
break;
}
}
}
for (int S = 0; S < (1 << maxd); ++S) {
for (int T = S; ; T = (T - 1) & S) {
int R = S ^ T;
if (f[(i - 1) & 1][T][R] == 0) {
continue;
}
inc(f[i & 1][(T << 1) & ((1 << maxd) - 1)][(R << 1) & ((1 << maxd) - 1)], f[(i - 1) & 1][T][R]);
if ((e[i] & R) == 0) {
inc(f[i & 1][(T << 1 | 1) & ((1 << maxd) - 1)][(R << 1) & ((1 << maxd) - 1)], f[(i - 1) & 1][T][R]);
}
if ((e[i] & T) == 0) {
inc(f[i & 1][(T << 1) & ((1 << maxd) - 1)][(R << 1 | 1) & ((1 << maxd) - 1)], f[(i - 1) & 1][T][R]);
}
if (T == 0) {
break;
}
}
}
}
int ans = 0;
for (int S = 0; S < (1 << maxd); ++S) {
for (int T = S; ; T = (T - 1) & S) {
inc(ans, f[n & 1][T][S ^ T]);
if (T == 0) {
break;
}
}
}
std::cout << ans / 2 << "\n";
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3 2 1 2 2 3