QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666864#7900. Gifts from KnowledgedyfhpuWA 0ms11708kbC++171.0kb2024-10-22 20:14:442024-10-22 20:14:47

Judging History

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

  • [2024-10-22 20:14:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11708kb
  • [2024-10-22 20:14:44]
  • 提交

answer

#include <iostream>
using namespace std;
typedef pair<int, int> PII;
const int mod=1e9+7;
const int N = 1000010;
int p[N];
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 solve()
{
	int r,c,ans=0,a[N]={0},b[N]={0};
	scanf("%d%d",&r,&c);
	string s;
	for(int i=1;i<=r;i++) p[i]=i;
	for(int i=1;i<=r;i++) {
		cin>>s;
		s=" "+s;
		for(int j=1;j<=c;j++) {
			if(s[j]=='1') {
				a[j]++;a[c-j+1]++;
				if(a[j]>2||a[c-j+1]>2) {
					printf("0\n");
					return ;
				}
				if(b[j]==0&&b[c-j+1]==0) {
					b[j]=i;
					b[c-j+1]=i;
				}else {
					int x=p[b[j]],y=p[i];
					if(x!=y) {
						p[y]=x;
					}
				}
			}
		}
	}
	for(int i=1;i<=r;i++) {
		if(p[i]==i) ans++;
		p[i]=0;
	}
	ans=power(2,ans);
	printf("%d\n",ans);
}
int main()
{
    int t = 1;
    cin >> t;
    std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    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: 11708kb

input:

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

output:

8
0
1024

result:

wrong answer 1st numbers differ - expected: '4', found: '8'