QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614544#7900. Gifts from Knowledgewsxcb#RE 0ms0kbC++171.9kb2024-10-05 16:33:012024-10-05 16:33:01

Judging History

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

  • [2024-10-05 16:33:01]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-05 16:33:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define se second

const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int fa[N << 1];

int find(int son) {
	return fa[son] == son ? son : fa[son] = find(fa[son]);
}

int merge(int u, int v) {
	int fau = find(u), fav = find(v);
	if (fau != fav)
		fa[fav] = fau;
}

void solve() {

	int n, m;
	cin >> n >> m;
	vector<string> s(n + 1);
	for (int i = 1 ; i <= n ; i++) {
		cin >> s[i];
		s[i] = " " + s[i];
	}

	for (int i = 1, j = m ; i <= j ; i++, j--) {
		int cnt = 0;
		for (int k = 1 ; k <= n ; k++) {
			int x1 = s[k][i] - '0', x2 = s[k][j] - '0';
			cnt += x1 + x2;
		}
		if (i == j) {
			cnt /= 2;
			if (cnt > 1) {
				cout << "0\n";
				return;
			}
		} else {
			if (cnt > 2) {
				cout << "0\n";
				return;
			}
		}
	}

	for (int i = 1 ; i <= 2 * n ; i++)
		fa[i] = i;
	for (int i = 1, j = m ; i < j ; i++, j--) {
		vector<int> lp, rp;
		for (int k = 1 ; k <= n ; k++) {
			int x1 = s[k][i] - '0', x2 = s[k][j] - '0';
			if (x1)
				lp.push_back(k);
			if (x2)
				rp.push_back(k);
		}
		if (lp.size() + rp.size() == 2) {
			if (lp.size() == 2) {
				int u = lp[0], v = lp[1];
				merge(u, v + n);
				merge(u + n, v);
			} else if (rp.size() == 2) {
				int u = rp[0], v = rp[1];
				merge(u, v + n);
				merge(u + n, v);
			} else {
				int u = lp[0], v = rp[0];
				merge(u, v);
				merge(u + n, v + n);
			}
		}
	}

	for (int i = 1 ; i <= n ; i++) {
		if (find(i) == find(i + n)) {
			cout << "0\n";
			return;
		}
	}

	ll ans = 0 ;
	for (int i = 1 ; i <= 2 * n ; i++) {
		if (find(i) == i)
			ans++;
	}
	ans /= 2;
	ll ret = 1;
	for (int i = 1 ; i <= ans ; i++) {
		ret = ret * 2ll % mod;
	}
	cout << ret << '\n';

}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: