QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#779890#7900. Gifts from KnowledgeHaijieTanWA 0ms3588kbC++232.0kb2024-11-24 22:36:222024-11-24 22:36:24

Judging History

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

  • [2024-11-24 22:36:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-11-24 22:36:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
 
struct DSU {
	vector<int>p;
	DSU(int n):p(n + 1){iota(p.begin(), p.end(), 0);}
	int find(int x) {
		return p[x] == x ? x : p[x] = find(p[x]);
	}
	void merge(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y)return;
		p[y] = x;
	}
};
const int mod = 1e9 + 7;
int qpow(int a, int b) {
	int ans = 1;
	while(b) {
		if(b & 1)ans = ans * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return ans;
}
 
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];
	}
	DSU d(2 * n);
	for(int j = 1; j <= m; j++) {
		int cnt = 0;
		vector<int> p;
		for(int i = 1; i <= n; i++) {
			if(s[i][j] == '1'){
				cnt++;
				p.push_back(i);
			}
			if(m - j + 1 != j && s[i][m - j + 1] == '1'){
				cnt++;
				p.push_back(i);
			}
		}
		if(cnt > 2) {
			cout << 0 << endl;
			return;
		}
		// cout << cnt << endl;
		if(cnt == 2 && m == 1) {
			cout << 0 << endl;
			return;
		}
		// if(j == 3) cout << cnt << endl;
		if(cnt == 2) {
			int a = p[0], b = p[1];
			// if(j == 3)cout << a << " " << b << endl;
			if(a == b) {
				continue;
			}
			else if(s[a][j] == s[b][j] && s[a][j] == '1') {//同边
				// cout << 1 << endl;
				d.merge(a, b + n);
				d.merge(b, a + n);
			}
			else if(s[a][m - j + 1] == s[b][m - j + 1] && s[a][j] == '1') {
				d.merge(a, b + n);
				d.merge(b, a + n);
			}
			else {//不同边
				d.merge(a, b);
				d.merge(a + n, b + n);
			}
		}
	}
	int ans = 0;
	vector<int>vis(2 * n + 1);
	for(int i = 1; i <= n; i++) {
		if(d.find(i) == d.find(i + n)) {
			cout << 0 << endl;
			return;
		}
	}
	for(int i = 1; i <= 2 * n; i++) {
		int t = d.find(i);
		if(vis[t])continue;
		ans++;
		vis[t] = 1;
	}
	ans /= 2;
	cout << qpow(2, ans) << endl;
}
 
#undef int
int main() {
	ios::sync_with_stdio(false);
	cin.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
Wrong Answer
time: 0ms
memory: 3588kb

input:

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

output:

4
0
0

result:

wrong answer 3rd numbers differ - expected: '2', found: '0'