QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#704293 | #5250. Combination Locks | nekoyellow | WA | 0ms | 3620kb | C++23 | 2.7kb | 2024-11-02 19:41:39 | 2024-11-02 19:41:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define odd(x) __builtin_parity(x)
class MF {
public:
MF(int _n, int _s, int _t): n(_n), s(_s), t(_t) {
head.assign(n, -1); dep.resize(n);
}
void addedge(int u, int v, int w) {
e.push_back({v, head[u], w, 0}); head[u] = e.size()-1;
e.push_back({u, head[v], 0, 0}); head[v] = e.size()-1;
}
ll dinic() {
ll maxflow = 0;
while (bfs()) cur = head, maxflow += dfs(s, inf);
return maxflow;
}
private:
static const int inf = numeric_limits<int>::max();
int n, s, t; // |V|, source, sink
struct Edge { int v, nxt, c, f; }; // to, next edge, capacity, flow
vector<Edge> e; vector<int> head; // linked forward repr
vector<int> dep, cur; // for dfs
bool bfs() {
queue<int> q; q.push(s);
fill(dep.begin(), dep.end(), 0); dep[s] = 1;
while (q.size()) {
int u = q.front(); q.pop();
for (int i = head[u]; ~i; i = e[i].nxt) {
int v = e[i].v;
if (!dep[v] && e[i].c > e[i].f) q.push(v), dep[v] = dep[u]+1;
}
}
return dep[t]; // if t is reachable from s
}
int dfs(int u, int flow) {
if (u == t || !flow) return flow;
int ret = 0;
for (int &i = cur[u]; ~i; i = e[i].nxt) {
int v = e[i].v;
if (dep[v] == dep[u]+1) {
int d = dfs(v, min(flow-ret, e[i].c-e[i].f));
if (!d) continue;
e[i].f += d, e[i^1].f -= d; ret += d;
if (ret == flow) break;
}
}
return ret;
}
};
void solve() {
int l, c;
cin >> l >> c;
string a, b;
cin >> a >> b;
int init = 0;
for (int i = 0; i < l; i++) {
if (a[i] != b[i]) init |= (1 << i);
}
int n = 1 << l;
vector<bool> bad(n);
for (; c; c--) {
string s;
cin >> s;
int x = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '.') x |= (1 << i);
}
bad[x] = 1;
}
int s = n, t = n+1;
MF mf(n+2, s, t);
for (int x = 0; x < n; x++) {
if (!odd(x)) continue;
for (int i = 0; i < l; i++) {
mf.addedge(x, x ^ (1 << i), 1);
}
}
for (int x = 0; x < n; x++) {
if (bad[x]) continue;
if (odd(x)) mf.addedge(s, x, 1);
else mf.addedge(x, t, 1);
}
cout << (mf.dinic() == 1 ? "Alice\n" : "Bob\n");
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
for (; t; t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
2 1 0 0 0 1 1 0 0 .
output:
Alice Bob
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3604kb
input:
8 2 0 00 00 2 1 00 00 .. 2 1 00 00 =. 2 2 00 00 .. =. 2 1 00 00 .= 2 2 00 00 .. .= 2 2 00 00 =. .= 2 3 00 00 .. =. .=
output:
Bob Alice Alice Alice Alice Alice Bob Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'