QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#715988 | #2549. King's Palace | Milkcat2009 | WA | 495ms | 36380kb | C++14 | 1.9kb | 2024-11-06 14:00:24 | 2024-11-06 14:00:24 |
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][c1][c2] |= 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] & S; 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 3616kb
input:
1 0
output:
3
result:
ok answer is '3'
Test #3:
score: 0
Accepted
time: 495ms
memory: 36380kb
input:
22 0
output:
31381059609
result:
ok answer is '31381059609'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
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:
33
result:
wrong answer expected '13', found '33'