QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#341387 | #7303. City United | SKHUO | WA | 26ms | 19944kb | C++14 | 1.7kb | 2024-02-29 18:21:10 | 2024-02-29 18:21:11 |
Judging History
answer
/*
WA因:状压13位而不是12位
TLE因:优化一下存图方式,避免枚举13个点来检测是否可染色
注意:只有合法状态有初值,且不合法状态不会被合法状态更新,所以
不需要在更新的时候可以避免枚举不合法状态(当然对于计数题不用将其看作
“不合法”,而是方案数为0)
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 55, S = 1600000;
int n, m;
int e[N], s[S][2];
int f[2][S]; // 滚一下
int pw[N];
void add(int &a, int b) { a = (a + b) % 4; }
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
if (u < v) swap(u, v);
e[u] |= 1 << (u - v - 1);
}
pw[0] = 1;
for (int i = 1; i <= 13; i++) pw[i] = pw[i - 1] * 3;
// 处理颜色对照表
for (int i = 0; i < pw[13]; i++) {
for (int j = 0; j < 13; j++) {
int bit = i / pw[j] % 3;
if (bit == 2) continue;
s[i][bit] |= 1 << j;
}
}
f[1][0] = f[1][1] = f[1][2] = 1;
for (int i = 1; i < n; i++) {
// int t = min(13, i);
for (int j = 0; j < 13; j++) {
int nj = (j - pw[12] * (j / pw[12])) * 3; // 注意要超出13位才去尾
// 注意+1
if (!(e[i + 1] & s[j][1])) add(f[(i + 1) & 1][nj + 0], f[i & 1][j]);
if (!(e[i + 1] & s[j][0])) add(f[(i + 1) & 1][nj + 1], f[i & 1][j]);
add(f[(i + 1) & 1][nj + 2], f[i & 1][j]);
f[i & 1][j] = 0; // 滚动数组要清这个
}
}
int ans = 0;
for (int j = 0; j < pw[13]; j++)
add(ans, f[n & 1][j]);
cout << ans / 2;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 26ms
memory: 19944kb
input:
3 2 1 2 2 3
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 25ms
memory: 18416kb
input:
3 3 1 2 2 3 3 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: -100
Wrong Answer
time: 25ms
memory: 19252kb
input:
15 31 9 5 14 5 2 7 5 15 11 14 11 9 2 6 3 4 12 1 6 8 3 5 11 10 15 6 4 1 1 2 8 9 6 12 14 10 13 2 4 5 3 8 3 15 11 6 7 5 4 6 11 2 13 15 3 2 8 4 6 13 7 10
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'