QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#71401 | #5250. Combination Locks | Sorting# | WA | 2ms | 3468kb | C++ | 2.6kb | 2023-01-09 21:58:49 | 2023-01-09 21:58:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
const int N = 10 + 3;
const int M = (1 << 10) + 3;
int n, c;
int start;
int forb[M];
bool is_forb[M];
bool dfs(int a, int L, vector<vector<int>> &g, vector<int> &btoa, vector<int> &A, vector<int> &B){
if(A[a] != L) return 0;
A[a] = -1;
for(int b: g[a]) if(B[b] == L + 1){
B[b] = 0;
if(btoa[b] == -1 || dfs(btoa[b], L + 1, g, btoa, A, B))
return btoa[b] = a, 1;
}
return 0;
}
int hopcroftKarp(vector<vector<int>> &g, vector<int> &btoa){
int res = 0;
vector<int> A(g.size()), B(btoa.size()), cur, next;
for(;;){
fill(A.begin(), A.end(), 0);
fill(B.begin(), B.end(), 0);
cur.clear();
for(int a: btoa) if(a != -1) A[a] = -1;
rep(a, 0, g.size()) if(A[a] == 0) cur.push_back(a);
for(int lay = 1;; ++lay){
bool islast = 0;
next.clear();
for(int a: cur) for(int b: g[a]){
if(btoa[b] == -1){
B[b] = lay;
islast = 1;
}
else if(btoa[b] != a && !B[b]){
B[b] = lay;
next.push_back(btoa[b]);
}
}
if(islast) break;
if(next.empty()) return res;
for(int a: next) A[a] = lay;
cur.swap(next);
}
rep(a, 0, g.size())
res += dfs(a, 0, g, btoa, A, B);
}
}
void solve(){
cin >> n >> c;
string a, b;
cin >> a >> b;
start = 0;
for(int i = 0; i < n; ++i)
start |= (a[i] == b[i]) << i;
fill(is_forb, is_forb + (1 << n), false);
for(int i = 0; i < c; ++i){
string f;
cin >> f;
forb[i] = 0;
for(int j = 0; j < n; ++j)
forb[i] |= (f[i] == '=') << j;
is_forb[forb[i]] = true;
}
vector<int> num(1 << n);
int cnt[2]{};
for(int i = 0; i < (1 << n); ++i){
int t = __builtin_popcount(i) & 1;
num[i] =cnt[t]++;
}
vector<vector<int>> g(1 << (n - 1));
for(int i = 0; i < (1 << n); ++i){
if(is_forb[i]) continue;
if(__builtin_popcount(i) & 1) continue;
for(int j = 0; j < n; ++j){
int x = i ^ (1 << j);
if(!is_forb[x])
g[num[i]].push_back(num[x]);
}
}
vector<int> btoa(1 << (n - 1), -1);
int before = hopcroftKarp(g, btoa);
for(int i = 0; i < (1 << (n - 1)); ++i)
g[i].clear();
is_forb[start] = true;
for(int i = 0; i < (1 << n); ++i){
if(__builtin_popcount(i) & 1) continue;
if(is_forb[i]) continue;
for(int j = 0; j < n; ++j){
int x = i ^ (1 << j);
if(!is_forb[x])
g[num[i]].push_back(num[x]);
}
}
btoa.clear();
btoa.resize(1 << (n - 1), -1);
int after = hopcroftKarp(g, btoa);
if(after == before)
cout << "Bob\n";
else
cout << "Alice\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3392kb
input:
2 1 0 0 0 1 1 0 0 .
output:
Alice Bob
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3468kb
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 Alice Bob Bob Alice
result:
wrong answer 5th lines differ - expected: 'Bob', found: 'Alice'