QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619975 | #7894. Many Many Heads | Orthos | WA | 1ms | 3608kb | C++20 | 2.5kb | 2024-10-07 16:11:58 | 2024-10-07 16:12:00 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int t;
ll r,c;
string s;
ll ans;
const ll mod=1e9+7;
vector<char> ve[1000005];
int f[1000005];
void init(){
for(int i=0;i<=2*r-1;i++){
f[i]=i;
}
}
int find(int x){
return f[x]!=x?f[x]=find(f[x]):x;
}
void merge(int x,int y){
int u=find(x),v=find(y);
if(u!=v){
f[v]=u;
}
return;
}
void Clear(){
for(int i=0;i<r;i++){
ve[i].clear();
}
}
void solve(){
cin>>r>>c;
init();
ans=1;
for(int i=0;i<r;i++) {
cin >> s;
for (int j = 0; j < c; j++) {
ve[i].push_back(s[j]);
}
}
for(int i=0;i<(c+1)/2;i++){
int cnt=0;
int f1=-1,f2=-1;
for(int j=0;j<r;j++){
if(ve[j][i]=='1'){
if(f1==-1){
f1=j;
}
else if(f2==-1){
f2=j;
}
else{
cout<<"0\n";
Clear();
return;
}
}
if(ve[j][c-i-1]=='1'&&c-i-1!=i){
if(f1==-1){
f1=j;
}
else if(f2==-1){
f2=j;
}
else{
cout<<"0\n";
Clear();
return;
}
}
}
if(c==1){
if(f2!=-1){
cout<<0<<"\n";
Clear();
return;
}
for(int i=1;i<=r;i++){
ans=ans*2%mod;
}
cout<<ans<<"\n";
Clear();
return ;
}
if(f1!=-1&&f2!=-1){
if(f1==f2){
merge(f1,f1);
merge(f1+r,f1+r);
}
else{
merge(f1,f2+r);
merge(f1+r,f2);
}
}
}
for(int i=0;i<r;i++){
if(find(i)==i+r){
cout<<0<<"\n";
Clear();
return;
}
}
int count=0;
for(int i=0;i<=2*r-1;i++){
if(find(i)==i){
count++;
}
}
for(int i=1;i<=count/2;i++){
ans=ans*2%mod;
}
cout<<ans<<"\n";
Clear();
return;
}
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
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: 1ms
memory: 3608kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
1 1 1 1 1 1
result:
wrong output format YES or NO expected, but 1 found [1st token]