QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#704412 | #5250. Combination Locks | nekoyellow | WA | 1ms | 3648kb | C++23 | 2.8kb | 2024-11-02 19:55:53 | 2024-11-02 19:56:04 |
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 start = 0;
for (int i = 0; i < l; i++) {
if (a[i] != b[i]) start |= (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] || x == start) continue;
if (odd(x)) mf.addedge(s, x, 1);
else mf.addedge(x, t, 1);
}
mf.dinic();
if (odd(start)) mf.addedge(s, start, 1);
else mf.addedge(start, 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
2 1 0 0 0 1 1 0 0 .
output:
Alice Bob
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
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:
Alice Alice Bob Alice Bob Alice Bob Bob
result:
ok 8 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
20 4 4 4714 5245 ..=. ..== .==. ==.. 4 1 2697 1438 .=.. 4 5 9255 0677 ...= ..== =..= ==.= ==== 4 12 3292 7326 ...= ..=. ..== .=.. .=.= .==. =... =..= =.== ==.. ==.= ==== 4 9 8455 2536 ...= ..== .=.. .=.= .==. .=== =... ==.. ===. 4 12 5755 1517 ...= ..=. ..== .=.. .=.= .=== =..= =.=. =.== ==.. ==.= =...
output:
Alice Bob Alice Bob Bob Alice Bob Bob Alice Alice Bob Alice Alice Bob Bob Bob Bob Bob Bob Bob
result:
ok 20 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
20 5 30 99942 90170 ..... ....= ...== ..=.. ..=.= ..==. ..=== .=... .=..= .=.=. .=.== .==.. .==.= .===. .==== =...= =..=. =..== =.=.. =.=.= =.==. =.=== ==... ==..= ==.=. ==.== ===.. ===.= ====. ===== 5 14 11760 95480 ...=. ...== ..=.. ..=.= .=... .=..= .==== =.... =...= =.=.. =.==. ==... ==.== =====...
output:
Bob Alice Alice Alice Alice Bob Bob Bob Alice Alice Alice Bob Alice Alice Alice Alice Alice Alice Alice Bob
result:
ok 20 lines
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
input:
20 6 62 188256 588825 ...... .....= ....=. ....== ...=.. ...=.= ...==. ...=== ..=... ..=..= ..=.=. ..=.== ..==.. ..==.= ..===. ..==== .=.... .=...= .=..=. .=..== .=.=.. .=.=.= .=.==. .=.=== .==..= .==.=. .==.== .===.. .===.= .===== =..... =....= =...=. =...== =..=.. =..=.= =..==. =..=== =.=... =.=.....
output:
Bob Alice Alice Alice Bob Bob Bob Alice Alice Alice Bob Bob Alice Bob Bob Bob Alice Bob Alice Bob
result:
wrong answer 2nd lines differ - expected: 'Bob', found: 'Alice'