QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#71398#5250. Combination LocksSorting#WA 2ms3384kbC++2.5kb2023-01-09 21:48:372023-01-09 21:48:40

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-09 21:48:40]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3384kb
  • [2023-01-09 21:48:37]
  • 提交

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){
		g[num[i]].clear();
		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);

	is_forb[start] = true;
	for(int i = 0; i < (1 << n); ++i){
		g[num[i]].clear();
		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]);
		}
	}

	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: 0
Wrong Answer
time: 2ms
memory: 3384kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Alice

result:

wrong answer 2nd lines differ - expected: 'Bob', found: 'Alice'