QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672747 | #7900. Gifts from Knowledge | xh_team# | WA | 0ms | 3752kb | C++20 | 2.6kb | 2024-10-24 18:41:24 | 2024-10-24 18:41:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1E9 + 7;
void no() {
cout << 0 << '\n';
}
void solve() {
int n, m;
cin >> n >> m;
vector<string> s(n);
vector<int> fix(m);
vector<vector<int>> p(m), h(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < m; j++) {
s[i][j] -= '0';
}
for (int l = 0, r = m - 1; l <= r; l++, r--) {
if (l == r) {
if (s[i][l]) fix[l]++;
} else {
if (s[i][l] && s[i][r]) {
fix[l]++, fix[r]++;
} else if (s[i][l]) {
p[l].emplace_back(i);
} else if (s[i][r]) {
p[r].emplace_back(i);
}
}
}
}
for (int l = 0, r = m - 1; l <= r; l++, r--) {
if (l == r) {
if (fix[l] > 1) return no();
} else {
if (fix[l] > 1) return no();
if (fix[l] == 1 && p[l].size() + p[r].size() > 0) return no();
if (p[l].size() + p[r].size() > 2) return no();
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!fix[j] && s[i][j]) {
h[i].emplace_back(j);
// cout << i << ' ' << j << endl;
}
}
}
vector<int> col(n, -1);
function<bool(int, int)> dfs = [&](int x, int o) {
// cout << x << endl;
col[x] = o;
for (int i : h[x]) {
for (int y : p[i]) {
if (col[y] == -1) {
if (!dfs(y, o ^ 1)) {
return false;
}
} else if (x != y && col[y] == col[x]) {
return false;
}
}
for (int y : p[m - i - 1]) {
if (col[y] == -1) {
if (!dfs(y, o ^ 1)) {
return false;
}
} else if (x != y && col[y] == col[x]) {
return false;
}
}
}
return true;
};
int res = 1;
for (int i = 0; i < n; i++) {
if (col[i] == -1 && !h[i].empty()) {
if (dfs(i, 0)) {
res = res * 2 % MOD;
} else {
res = 0;
}
}
}
cout << res << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3752kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
2 0 2
result:
wrong answer 1st numbers differ - expected: '4', found: '2'