QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#101346#5250. Combination LocksDestroyXuanQuang#WA 2ms3456kbC++232.8kb2023-04-29 10:50:232023-04-29 10:50:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-29 10:50:24]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3456kb
  • [2023-04-29 10:50:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct UF {
	vi e;
	UF(int n) : e(n, -1) {}
	bool sameSet(int a, int b) { return find(a) == find(b); }
	int size(int x) { return -e[find(x)]; }
	int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
	bool join(int a, int b) {
		a = find(a), b = find(b);
		if (a == b) return false;
		if (e[a] > e[b]) swap(a, b);
		e[a] += e[b]; e[b] = a;
		return true;
	}
};

bool dfs(int a, int L, vector<vi>& g, vi& btoa, vi& A, vi& 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<vi>& g, vi& btoa) {
	int res = 0;
	vi A(g.size()), B(btoa.size()), cur, next;
	for (;;) {
		fill(all(A), 0);
		fill(all(B), 0);
		/// Find the starting nodes for BFS (i.e. layer 0).
		cur.clear();
		for (int a : btoa) if(a != -1) A[a] = -1;
		rep(a,0,sz(g)) if(A[a] == 0) cur.push_back(a);
		/// Find all layers using bfs.
		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);
		}
		/// Use DFS to scan for augmenting paths.
		rep(a,0,sz(g))
			res += dfs(a, 0, g, btoa, A, B);
	}
}

void solve() {
	int n, m; cin >> n >> m;
	string p1, p2; cin >> p1 >> p2;

	int st = 0;
	for (int i = 0; i < n; i++) {
		st <<= 1;
		if (p1[i] == p2[i]) {
			st |= 1;
		}
	}

	vector<int> ban(1 << n);
	for (int i = 0; i < m; i++) {
		string s; cin >> s;
		int msk = 0;
		for (char c: s) {
			msk <<= 1;
			if (c == '=') msk |= 1;
		}
		ban[msk] = 1;
	}

	UF d(1 << n);

	vector<vi> g(1 << n);
	for (int i = 0; i < (1 << n); i++) {
		for (int b = 0; b < n; b++) {
			int j = i ^ (1 << b);
			if (ban[i] || ban[j]) continue;
			d.join(i, j);
			if ((__builtin_popcount(i) % 2) == 0) {
				g[i].push_back(j);
			}
		}
	}

	vi btoa((1 << n), -1); 
	hopcroftKarp(g, btoa);

	int sz = 0;
	for (int i = 0; i < (1 << n); i++) {
		if (d.sameSet(i, st)) sz++;
	}

	int pm = 0;
	for (int i = 0; i < (1 << n); i++) {
		if (d.sameSet(i, st) && btoa[i] != -1) {
			pm++;
		}
	}

	if (pm*2 == sz) {
		cout << "Alice\n";
	} else {
		cout << "Bob\n";
	}
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	int t; cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3456kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3456kb

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
Bob
Bob
Alice
Bob
Alice
Bob
Bob

result:

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