QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666465#7900. Gifts from KnowledgedyfhpuTL 0ms35800kbC++171.1kb2024-10-22 18:37:382024-10-22 18:37:49

Judging History

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

  • [2024-10-22 18:37:49]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:35800kb
  • [2024-10-22 18:37:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> PII;
const int mod=1e9+7;
const int N = 1000010;
vector<int> v[N];
bool st[N+10];
long long power(int a, int b){
	long long res = 1;
	while (b){
		if (b & 1) res = res * a % mod;
		b >>= 1;
		a = a * a % mod;
		
	}
	return res;
}
void dfs(int x) {
	for(auto f:v[x]) {
		if(st[f]==1) continue;
		st[f]=1;
		dfs(f);
	}
}
void solve()
{
	int r,c,ans=0,a[N]={0},b[N]={0};
	cin>>r>>c;
	string s[r+10];
	memset(st,0,sizeof st);
	for(int i=1;i<=r;i++) {
		cin>>s[i];
		s[i]=" "+s[i];
		for(int j=1;j<=c;j++) {
			if(s[i][j]=='1') {
				a[j]++;a[c-j+1]++;
				if(a[j]>2||a[c-j+1]>2) {
					cout<<0<<endl;
					return ;
				}
				if(b[j]==0&&b[c-j+1]==0) {
					b[j]=i;
					b[c-j+1]=i;
				}else {
					v[i].push_back(b[j]);
					v[b[j]].push_back(i);
				}
			}
		}
	}
	for(int i=1;i<=r;i++) {
		if(st[i]==0) {
			dfs(i);ans++;
		}
	}
	for(int i=1;i<=r;i++) {
		v[i].clear();
	}
	cout<<power(2,ans)<<endl;
}
int main()
{
    int t = 1;
    cin >> t;
    
    while (t--)
        solve();
    
    return 0;
}

详细

Test #1:

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

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
Time Limit Exceeded

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:

1024
32768
2
32
32768
128
32
16
16
2
16384
16384
128
128
32768
8192
128
64
16384
2
4
2
4096
16
4096
1024
32768
32768
16384
8
128
2
16
4096
8192
32768
8192
8192
16
16384
16384
256
128
8
256
8
4096
512
2
4
32
32
2
64
512
1024
32768
32768
2
64
16384
16
8192
16
256
16
64
8192
8192
64
1024
2
32768
2
4
51...

result: