QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#139347 | #5250. Combination Locks | UNos_maricones | WA | 1ms | 3540kb | C++20 | 3.3kb | 2023-08-13 01:52:15 | 2023-08-13 01:52:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std ;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double lf;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll SQ = 800;
const ll N = 3e5+5;
const ll mod = 1e9+7;
const ll oo = 1e18;
/// Complexity: O(|E|*|V|^2)
/// Tested: https://tinyurl.com/ya9rgoyk
struct edge { int v, cap, inv, flow; };
struct network {
int n, s, t;
vector<int> lvl;
vector<vector<edge>> g;
network(int n) : n(n), lvl(n), g(n) {}
void add_edge(int u, int v, int c) {
g[u].push_back({v, c, g[v].size(), 0});
g[v].push_back({u, 0, g[u].size()-1, c});
}
bool bfs() {
fill(lvl.begin(), lvl.end(), -1);
queue<int> q;
lvl[s] = 0;
for(q.push(s); q.size(); q.pop()) {
int u = q.front();
for(auto &e : g[u]) {
if(e.cap > 0 && lvl[e.v] == -1) {
lvl[e.v] = lvl[u]+1;
q.push(e.v);
}
}
}
return lvl[t] != -1;
}
int dfs(int u, int nf) {
if(u == t) return nf;
int res = 0;
for(auto &e : g[u]) {
if(e.cap > 0 && lvl[e.v] == lvl[u]+1) {
int tf = dfs(e.v, min(nf, e.cap));
res += tf; nf -= tf; e.cap -= tf;
g[e.v][e.inv].cap += tf;
g[e.v][e.inv].flow -= tf;
e.flow += tf;
if(nf == 0) return res;
}
}
if(!res) lvl[u] = -1;
return res;
}
int max_flow(int so, int si, int res = 0) {
s = so; t = si;
while(bfs()) res += dfs(s, INT_MAX);
return res;
}
};
int main(){
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t; cin >> t;
while (t--) {
int n, c; cin >> n >> c;
string s1, s2; cin >> s1 >> s2;
int s = 0;
for (int i = 0; i < n; ++i) {
if (s1[i] == s2[i]) s ^= (1<<i);
}
vector <int> forb((1<<n));
for (int i = 0; i < c; ++i) {
string x; cin >> x;
int rx = 0;
for (int j = 0; j < n; ++j) {
if (x[j] == '=') rx ^= (1<<j);
}
forb[rx] = 1;
}
int oness = __builtin_popcount(s);
network net(2 + (1<<n));
for (int i = 0; i < (1<<n); ++i) {
int onesi = __builtin_popcount(i);
if (onesi % 2 == oness % 2) {
net.add_edge(0, i + 1, 1);
for (int j = 0; j < n; ++j) {
int cn = i ^ (1<<j);
if (!forb[i] && !forb[cn]) {
net.add_edge(i + 1, cn + 1, 1);
}
}
}
else net.add_edge(i + 1, 1 + (1<<n), 1);
}
net.max_flow(0, 1 + (1<<n));
queue <int> q;
q.push(s);
vector <int> visi(2 + (1<<n));
visi[s]=1;
while (q.size()) {
int curr = q.front(); q.pop();
for (auto &e : net.g[curr]) {
if (((e.v % 2 == s % 2 && e.cap == 0) || e.v % 2 != s % 2) && !visi[e.v]) {
q.push(e.v);
visi[e.v]=1;
}
}
}
int can = 1;
for (auto &e : net.g[0]) {
// cout << e.v << ' ' << e.cap << ' ' << visi[e.v] << '\n';
if (e.cap && visi[e.v])
can=0;
}
if (can) cout << "Alice\n";
else cout << "Bob\n";
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3540kb
input:
2 1 0 0 0 1 1 0 0 .
output:
Alice Alice
result:
wrong answer 2nd lines differ - expected: 'Bob', found: 'Alice'