QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#716038 | #2549. King's Palace | Milkcat2009 | TL | 473ms | 36380kb | C++14 | 1.9kb | 2024-11-06 14:08:50 | 2024-11-06 14:08:50 |
Judging History
answer
#include <bits/stdc++.h>
#define REP(i, l, r) for (int i = (l); i <= (r); ++ i)
#define DEP(i, r, l) for (int i = (r); i >= (l); -- i)
#define fi first
#define se second
#define pb emplace_back
#define mems(x, v) memset((x), (v), sizeof(x))
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
namespace Milkcat {
typedef long long LL;
typedef pair<LL, LL> pii;
const int N = 22;
LL n, m, rs, x, y, c1, c2, c[N], q[N * 2], f[1 << N], g[N][3][3]; char s1, s2;
int main() {
cin >> n >> m;
REP(i, 1, m) {
cin >> x >> s1 >> y >> s2, x --, y --;
c1 = (s1 == 'R' ? 0 : (s1 == 'G' ? 1 : 2));
c2 = (s2 == 'R' ? 0 : (s2 == 'G' ? 1 : 2));
g[x][c1][c2] |= 1 << y, g[y][c2][c1] |= 1 << x;
}
f[0] = 1;
REP(S, 1, (1 << n) - 1) {
int x = __lg(S & -S);
for (int v : {0, 1}) {
int T = 0, chk = 1, l = 1, r = 0;
mems(c, -1), c[x] = v, q[++ r] = x;
while (l <= r) {
int u = q[l ++]; T |= 1 << u;
for (int w : {0, 1})
for (int t = g[u][c[u]][w] & S; t; t &= t - 1) {
int v = __lg(t & -t);
if (c[v] == -1) c[v] = !w, q[++ r] = v;
else chk &= (c[v] != w);
}
}
if (chk) f[S] += f[S ^ T];
}
}
REP(S, 0, (1 << n) - 1) {
int chk = 1, T = (1 << n) - 1, l = 1, r = 0;
REP(i, 0, n - 1) {
c[i] = -1;
if (S >> i & 1) c[i] = 2, q[++ r] = i;
}
while (l <= r) {
int u = q[l ++]; T ^= 1 << u;
for (int w : {0, 1, 2})
for (int t = g[u][c[u]][w]; t; t &= t - 1) {
int v = __lg(t & -t);
if (w != 2 && c[v] == -1) c[v] = !w, q[++ r] = v;
else chk &= (c[v] != w);
}
}
if (chk) rs += f[T];
}
cout << rs << '\n';
return 0;
}
}
int main() {
// freopen("paint.in", "r", stdin);
// freopen("paint.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
while (T --) Milkcat::main();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
2 3 1 R 2 R 1 G 2 R 1 B 2 G
output:
6
result:
ok answer is '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
1 0
output:
3
result:
ok answer is '3'
Test #3:
score: 0
Accepted
time: 473ms
memory: 36380kb
input:
22 0
output:
31381059609
result:
ok answer is '31381059609'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
4 12 2 R 3 R 1 B 2 B 2 R 3 B 3 R 4 R 1 B 4 G 1 R 3 B 3 G 4 B 2 G 3 G 1 B 2 R 1 G 2 R 1 R 3 G 1 G 3 B
output:
13
result:
ok answer is '13'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 4 1 G 2 G 1 B 2 R 1 R 2 G 1 B 2 B
output:
5
result:
ok answer is '5'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 77 3 B 5 B 2 G 5 G 4 R 5 G 1 G 2 B 1 R 4 R 4 B 5 G 2 B 3 G 2 G 5 B 1 R 3 G 2 R 5 R 3 B 4 R 1 R 2 B 3 G 4 G 1 B 5 G 3 R 5 G 3 G 4 B 1 B 4 G 4 B 5 R 2 R 4 G 1 G 4 B 2 G 3 R 2 R 5 B 1 G 2 R 2 B 4 R 2 R 3 R 3 B 5 G 2 G 3 G 1 R 3 R 1 R 5 G 2 G 3 B 3 B 4 B 4 R 5 B 1 R 2 G 3 G 5 R 1 R 2 R 2 B 5 B 3 B 5 R...
output:
0
result:
ok answer is '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
10 141 3 B 9 B 1 R 8 R 4 B 8 R 2 B 4 R 2 R 7 B 6 B 9 R 1 R 9 R 4 R 8 G 3 B 8 R 3 B 5 G 4 B 9 B 4 G 5 R 2 R 3 G 7 B 8 G 5 B 7 R 7 B 8 R 2 B 8 B 7 R 10 B 2 G 10 G 6 G 8 B 1 R 4 B 8 R 10 B 2 G 3 B 2 B 5 B 3 R 4 R 3 B 7 R 3 R 7 R 2 R 10 R 3 G 9 G 5 B 10 G 6 R 8 B 3 R 9 G 1 B 10 G 3 R 8 G 1 B 3 R 4 R 9 R...
output:
0
result:
ok answer is '0'
Test #8:
score: -100
Time Limit Exceeded
input:
22 2079 1 R 2 R 1 R 2 G 1 R 2 B 1 G 2 R 1 G 2 G 1 G 2 B 1 B 2 R 1 B 2 G 1 B 2 B 1 R 3 R 1 R 3 G 1 R 3 B 1 G 3 R 1 G 3 G 1 G 3 B 1 B 3 R 1 B 3 G 1 B 3 B 1 R 4 R 1 R 4 G 1 R 4 B 1 G 4 R 1 G 4 G 1 G 4 B 1 B 4 R 1 B 4 G 1 B 4 B 1 R 5 R 1 R 5 G 1 R 5 B 1 G 5 R 1 G 5 G 1 G 5 B 1 B 5 R 1 B 5 G 1 B 5 B 1 R ...