QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#631822#7900. Gifts from KnowledgePepinotRE 0ms3552kbC++202.2kb2024-10-12 10:27:252024-10-12 10:27:25

Judging History

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

  • [2024-10-12 10:27:25]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3552kb
  • [2024-10-12 10:27:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
const int mod = 1e9 + 7;
int n, m;

struct DSU{
	vector<int> fa;
	DSU(int n) : fa(n) {
		for(int i = 0; i < n; i++){
			fa[i] = i;
		}
	} 
	int find(int x){
		if (fa[x] != x) fa[x] = find(fa[x]);
		return fa[x];
	}
	void merge(int x, int y){
		if(find(x) != find(y)){
			fa[find(x)] = find(y);
		}
	}
}; 

void solve(){
	int res = 0;
	cin >> n >> m;
	vector<vector<int>> a(n + 5, vector<int>(m + 5));
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			char ch;
			cin >> ch;
			a[i][j] = ch - '0';
		}
	}
	DSU d(2 * n + 5);
	for(int j = 1; j <= m / 2; j++){
		vector<int> vec[2];
		for(int i = 1; i <= n; i++){
			if(a[i][j]) vec[0].pb(i);
			if(a[i][m - j + 1]) vec[1].pb(i);
		}
		if(vec[0].size() + vec[1].size() > 2){
			cout << 0 << '\n';
			return;
		}
//		for(int x = 0; x < 2; x++)
//			for(int y = 0; y < vec[x].size(); y++)
//				for(int z = y + 1; z < vec[x].size(); z++){
//					int u = vec[x][y], v = vec[x][z];
//					d.merge(u + n, v);
//					d.merge(u, v + n);
//				}
//		if(vec[0].size()+vec[1].size()==2){
			if(vec[0].size() && vec[1].size()){
				int u = vec[0][0], v = vec[1][0];
				d.merge(u, v);
				d.merge(u + n, v + n);
			}
			else{
				if(vec[0].size()){
					int u = vec[0][0], v = vec[0][1];
					d.merge(u, v);
					d.merge(u + n, v + n);
				}
				else{
					int u = vec[1][0], v = vec[1][1];
					d.merge(u, v);
					d.merge(u + n, v + n);
				}
			}
//		}
		
	}
	if(m % 2 == 1){
		int j = (m + 1) / 2;
		vector<int> vec;
		for(int i = 1; i <= n; i++)
			if(a[i][j]) vec.pb(i);
		
		if(vec.size() > 1){
			cout << 0 << '\n';
			return;
		}
	}
	
	for(int i = 1; i <= n; i++)
		if(d.find(i) == d.find(i + n)){
			cout << 0 << '\n';
			return;
		}
	
	int cnt = 0;
	for(int i = 1; i <= 2 * n; i++)
		if(d.find(i) == i) cnt++;
	
	cnt /= 2;
	res = 1;
	for(int i = 1; i <= cnt; i++){
		res = res * 2 % mod;
	}
	cout << res << '\n';
}   

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

詳細信息

Test #1:

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

input:

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

output:

4
0
2

result:

ok 3 number(s): "4 0 2"

Test #2:

score: -100
Runtime Error

input:

15613
10 10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
15 8
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
1 5
00000
5 9
000000000
000000000
0000...

output:


result: