QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709539 | #7900. Gifts from Knowledge | MIS_T__ | Compile Error | / | / | C++23 | 4.8kb | 2024-11-04 15:19:24 | 2024-11-04 15:19:25 |
Judging History
answer
#include <bits/stdc++.h>#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 mod = 1000000007;
void solve() {
int n,m;
cin >> n >> m;
vector G(m,vector<int>(0));
vector g(n,vector<int>(0));
string S[n];
for ( int i = 0 ; i < n ; i++ ) {
string s;
cin >> s;
S[i] = s;
for ( int j = 0 ; j < m ; j++ ) {
if ( s[j] == '1' ) {
g[i].emplace_back(j);
g[i].emplace_back(m-1-j);
G[j].emplace_back(i);
G[m-1-j].emplace_back(i);
}
}
}
for ( int i = 0 ; i < m ; i++ ) {
if ( G[i].size() >= 3 ) {
cout << 0 << '\n';
return;
}
}
// 5 0 1 2 3 4 5 6
i64 res = 1;
vector<int>vis(n,-1);
for ( int i = 0 ; i < n ; i++ ) {
if ( vis[i] == -1 ) {
queue<pair<int,int>>q;
q.emplace(i,0);
vis[i] = 0;
vector<int>A,B;
B.emplace_back(i);
while ( q.size() ) {
auto [u,cur] = q.front();
q.pop();
for ( auto k : g[u] ) {
for ( auto v : G[k] ) {
if ( u == v ) continue;
if ( vis[v] == -1 ) {
vis[v] = (cur^1);
q.emplace(v,cur^1);
if ( (cur^1) ) A.emplace_back(v);
else B.emplace_back(v);
} else if ( vis[v] == cur ) {
cout << 0 << '\n';
return;
}
}
}
}
vector<int>U(m),V(m);
for ( auto k : A ) {
for ( int j = 0 ; j < m ; j++ ) {
if ( S[k][j] == '1' ) {
if ( U[j] == 1 ) {
cout << 0 << '\n';
return;
} else {
U[j] = 1;
}
}
}
}
for ( auto k : B ) {
for ( int j = 0 ; j < m ; j++ ) {
if ( S[k][j] == '1' ) {
if ( V[j] == 1 ) {
cout << 0 << '\n';
return;
} else {
V[j] = 1;
}
}
}
}
reverse(B.begin(),B.end());
for ( int j = 0 ; j < m ; j++ ) {
// cout << U[j] << V[j] << '\n';
if ( (U[j]&V[j]) ) {
cout << 0 << '\n';
return;
}
}
res = res*2%mod;
}
}
cout << res << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while ( T-- ) {
solve();
}
}
using namespace std;
using i64 = long long;
const i64 mod = 1000000007;
void solve() {
int n,m;
cin >> n >> m;
vector G(m,vector<int>(0));
vector g(n,vector<int>(0));
for ( int i = 0 ; i < n ; i++ ) {
string s;
cin >> s;
for ( int j = 0 ; j < m ; j++ ) {
if ( s[j] == '1' ) {
g[i].emplace_back(j);
g[i].emplace_back(m-1-j);
G[j].emplace_back(i);
G[m-1-j].emplace_back(i);
}
}
}
for ( int i = 0 ; i < m ; i++ ) {
if ( G[i].size() >= 3 ) {
cout << 0 << '\n';
return;
}
}
// 5 0 1 2 3 4 5 6
i64 res = 1;
vector<int>vis(n,-1);
for ( int i = 0 ; i < n ; i++ ) {
if ( vis[i] == -1 ) {
queue<pair<int,int>>q;
q.emplace(i,0);
vis[i] = 0;
while ( q.size() ) {
auto [u,cur] = q.front();
q.pop();
for ( auto k : g[u] ) {
for ( auto v : G[k] ) {
if ( u == v ) continue;
if ( vis[v] == -1 ) {
vis[v] = (cur^1);
q.emplace(v,cur^1);
} else if ( vis[v] == cur ) {
cout << 0 << '\n';
return;
}
}
}
}
res = res*2%mod;
}
}
cout << res << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while ( T-- ) {
solve();
}
}
Details
answer.code:1:25: warning: extra tokens at end of #include directive 1 | #include <bits/stdc++.h>#include <bits/stdc++.h> | ^ answer.code:109:11: error: redefinition of ‘const i64 mod’ 109 | const i64 mod = 1000000007; | ^~~ answer.code:4:11: note: ‘const i64 mod’ previously defined here 4 | const i64 mod = 1000000007; | ^~~ answer.code:110:6: error: redefinition of ‘void solve()’ 110 | void solve() { | ^~~~~ answer.code:5:6: note: ‘void solve()’ previously defined here 5 | void solve() { | ^~~~~ answer.code:163:5: error: redefinition of ‘int main()’ 163 | int main() { | ^~~~ answer.code:98:5: note: ‘int main()’ previously defined here 98 | int main() { | ^~~~