QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#582745#7900. Gifts from KnowledgeccsurzwWA 0ms3596kbC++201.6kb2024-09-22 17:20:332024-09-22 17:20:36

Judging History

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

  • [2024-09-22 17:20:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-09-22 17:20:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
const int inf = 0x3f3f3f3f;


int n, m;
ll ksm(ll x, ll y) {
	ll sum = 1;
	while (y) {
		if (y & 1)sum = x * sum % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return sum;
}
int find(int x, vector<int> & fa) {
	return fa[x] == x ? x : fa[x] = find(fa[x] , fa);
}
void solve() {
	cin >> n >> m;
	vector<int> fa(n * 2 + 2);
	for (int i = 0; i < 2 * n; i++)fa[i] = i;
	vector<string> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int j = 1; j <= (m + 1) / 2; j++) {
		vector<pair<int, int>> e;
		for (int i = 0; i < n; i++) {
			if (a[i][j] == '1')e.push_back({i , j});
			if(a[i][m + 1 - j] == '1')e.push_back({i , m + 1 - j});
		}
		if (e.size() > 2) {
			cout << 0 << endl;
			return;
		}
		if (e.size() == 2 && e[0].first != e[1].first ) {
			int u1 = find(e[1].first, fa), v1 = find(e[0].first, fa);
			int u2 = find(e[1].first + n, fa), v2 = find(e[0].first + n ,fa);
			if (e[0].second == e[1].second) {
				fa[u1] = v2;
				fa[u2] = v1;
			}
			else {
				fa[u1] = v1;
				fa[u2] = v2;
			}
		}
	}
	ll cnt = 0;
	for (int i = 0; i < n; i++) {
		int u = find(i ,fa), v = find(i + n, fa);
		if (fa[i] == i)cnt++;
		if (fa[i + n] == i + n) cnt++;
		if (u == v) {
			cout << 0 << endl;
			return;
		}
	}
	cnt >>= 1;
	cout << ksm(2, cnt) << endl;
}

signed main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

3
3 5
01100
10001
00010
2 1
1
1
2 3
001
001

output:

4
4
4

result:

wrong answer 2nd numbers differ - expected: '0', found: '4'