QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203074#5250. Combination Locksucup-team288#WA 1ms3552kbC++203.2kb2023-10-06 15:15:022023-10-06 15:15:02

Judging History

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

  • [2023-10-06 15:15:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3552kb
  • [2023-10-06 15:15:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using ll = long long;
#define pb emplace_back
#define X first
#define Y second
#define AI(i) begin(i), end(i)
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true);}
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true);}
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l++ << " \n"[l==r]; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

const int MAX_N = 300010;

struct BipartiteMatching {
	int n, m;
	vector<vector<int>> adj;
	vector<int> l, r, dis, cur;
	BipartiteMatching(int n, int m) : n(n), m(m), adj(n), l(n, -1), r(m, -1), dis(n), cur(n) {}
	void addEdge(int u, int v) { adj[u].push_back(v); }
	void bfs() {
		vector<int> q;
		for (int i = 0; i < n; i++) {
			if (l[i] == -1) {
				dis[i] = 0;
				q.push_back(i);
			} else {
				dis[i] = -1;
			}
		}
		for (int i = 0; i < int(q.size()); i++) {
			int u = q[i];
			for (auto v : adj[u]) {
				if (r[v] != -1 && dis[r[v]] == -1) {
					dis[r[v]] = dis[u] + 1;
					q.push_back(r[v]);
				}
			}
		}
	}
	bool dfs(int u) {
		for (int &i = cur[u]; i < int(adj[u].size()); i++) {
			int v = adj[u][i];
			if (r[v] == -1 || dis[r[v]] == dis[u] + 1 && dfs(r[v])) {
				l[u] = v;
				r[v] = u;
				return true;
			}
		}
		return false;
	}
	bool maxMatching(int rem) {
		int match = 0;
		while (true) {
			bfs();
			int cnt = 0;
			fill(cur.begin(), cur.end(), 0);
			for (int i = 0; i < n; i++) {
				if (i == rem) {
					continue;
				}
				if (l[i] == -1) {
					cnt += dfs(i);
				}
			}
			if (cnt == 0) {
				break;
			}
			match += cnt;
		}
		fill(cur.begin(), cur.end(), 0);
		return dfs(rem);
	}
};

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);

	int t;
	cin >> t;

	auto solve = [&]() {
		int n, m;
		cin >> n >> m;

		int S = 0;

		{
			string s, t;
			cin >> s >> t;
			for (int i = 0; i < n; i++) {
				S |= (s[i] != t[i]) << i;
			}
		}

		vector<int> ban(1 << n);
		for (int i = 0; i < m; i++) {
			string a;
			cin >> a;
			int s = 0;
			for (int j = 0; j < n; j++) {
				s |= (a[j] == '.') << j;
			}
			ban[s] = true;
		}

		vector<int> dis(1 << n, -1), q{S}, cnt(2), id(1 << n, -1);
		dis[S] = 0;
		for (int i = 0; i < int(q.size()); i++) {
			int u = q[i];
			id[u] = cnt[dis[u] % 2 != dis[S] % 2]++;
			for (int v = 0; v < 1 << n; v++) {
				if (__builtin_popcount(u ^ v) == 1 && dis[v] == -1 && !ban[v]) {
					q.push_back(v);
					dis[v] = dis[u] + 1;
				}
			}
		}

		BipartiteMatching bm(cnt[0], cnt[1]);

		for (int s = 0; s < 1 << n; s++) {
			if (dis[s] % 2 != 0) {
				continue;
			}
			int u = id[s];
			for (int i = 0; i < n; i++) {
				int t = s ^ 1 << i;
				int v = id[t];
				if (v == -1) {
					continue;
				}
				bm.addEdge(u, v);
			}
		}

		bool alice = bm.maxMatching(id[S]);
		cout << (alice ? "Alice" : "Bob") << '\n';
	};

	while (t--) {
		solve();
	}
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3544kb

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

result:

ok 8 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

20
4 4
4714
5245
..=.
..==
.==.
==..
4 1
2697
1438
.=..
4 5
9255
0677
...=
..==
=..=
==.=
====
4 12
3292
7326
...=
..=.
..==
.=..
.=.=
.==.
=...
=..=
=.==
==..
==.=
====
4 9
8455
2536
...=
..==
.=..
.=.=
.==.
.===
=...
==..
===.
4 12
5755
1517
...=
..=.
..==
.=..
.=.=
.===
=..=
=.=.
=.==
==..
==.=
=...

output:

Alice
Bob
Alice
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Bob
Bob

result:

ok 20 lines

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3488kb

input:

20
5 30
99942
90170
.....
....=
...==
..=..
..=.=
..==.
..===
.=...
.=..=
.=.=.
.=.==
.==..
.==.=
.===.
.====
=...=
=..=.
=..==
=.=..
=.=.=
=.==.
=.===
==...
==..=
==.=.
==.==
===..
===.=
====.
=====
5 14
11760
95480
...=.
...==
..=..
..=.=
.=...
.=..=
.====
=....
=...=
=.=..
=.==.
==...
==.==
=====...

output:

Bob
Alice
Alice
Alice
Alice
Alice
Bob
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Bob

result:

wrong answer 6th lines differ - expected: 'Bob', found: 'Alice'