QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#779890 | #7900. Gifts from Knowledge | HaijieTan | WA | 0ms | 3588kb | C++23 | 2.0kb | 2024-11-24 22:36:22 | 2024-11-24 22:36:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
struct DSU {
vector<int>p;
DSU(int n):p(n + 1){iota(p.begin(), p.end(), 0);}
int find(int x) {
return p[x] == x ? x : p[x] = find(p[x]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if(x == y)return;
p[y] = x;
}
};
const int mod = 1e9 + 7;
int qpow(int a, int b) {
int ans = 1;
while(b) {
if(b & 1)ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
return ans;
}
void solve() {
int n, m;
cin >> n >> m;
vector<string> s(n + 1);
for(int i = 1; i <= n; i++) {
cin >> s[i];
s[i] = " " + s[i];
}
DSU d(2 * n);
for(int j = 1; j <= m; j++) {
int cnt = 0;
vector<int> p;
for(int i = 1; i <= n; i++) {
if(s[i][j] == '1'){
cnt++;
p.push_back(i);
}
if(m - j + 1 != j && s[i][m - j + 1] == '1'){
cnt++;
p.push_back(i);
}
}
if(cnt > 2) {
cout << 0 << endl;
return;
}
// cout << cnt << endl;
if(cnt == 2 && m == 1) {
cout << 0 << endl;
return;
}
// if(j == 3) cout << cnt << endl;
if(cnt == 2) {
int a = p[0], b = p[1];
// if(j == 3)cout << a << " " << b << endl;
if(a == b) {
continue;
}
else if(s[a][j] == s[b][j] && s[a][j] == '1') {//同边
// cout << 1 << endl;
d.merge(a, b + n);
d.merge(b, a + n);
}
else if(s[a][m - j + 1] == s[b][m - j + 1] && s[a][j] == '1') {
d.merge(a, b + n);
d.merge(b, a + n);
}
else {//不同边
d.merge(a, b);
d.merge(a + n, b + n);
}
}
}
int ans = 0;
vector<int>vis(2 * n + 1);
for(int i = 1; i <= n; i++) {
if(d.find(i) == d.find(i + n)) {
cout << 0 << endl;
return;
}
}
for(int i = 1; i <= 2 * n; i++) {
int t = d.find(i);
if(vis[t])continue;
ans++;
vis[t] = 1;
}
ans /= 2;
cout << qpow(2, ans) << endl;
}
#undef int
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
4 0 0
result:
wrong answer 3rd numbers differ - expected: '2', found: '0'