QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#71401#5250. Combination LocksSorting#WA 2ms3468kbC++2.6kb2023-01-09 21:58:492023-01-09 21:58:50

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:58:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3468kb
  • [2023-01-09 21:58:49]
  • 提交

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();
} 

詳細信息

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'