QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#582745 | #7900. Gifts from Knowledge | ccsurzw | WA | 0ms | 3596kb | C++20 | 1.6kb | 2024-09-22 17:20:33 | 2024-09-22 17:20:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
const int inf = 0x3f3f3f3f;
int n, m;
ll ksm(ll x, ll y) {
ll sum = 1;
while (y) {
if (y & 1)sum = x * sum % mod;
x = x * x % mod;
y >>= 1;
}
return sum;
}
int find(int x, vector<int> & fa) {
return fa[x] == x ? x : fa[x] = find(fa[x] , fa);
}
void solve() {
cin >> n >> m;
vector<int> fa(n * 2 + 2);
for (int i = 0; i < 2 * n; i++)fa[i] = i;
vector<string> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int j = 1; j <= (m + 1) / 2; j++) {
vector<pair<int, int>> e;
for (int i = 0; i < n; i++) {
if (a[i][j] == '1')e.push_back({i , j});
if(a[i][m + 1 - j] == '1')e.push_back({i , m + 1 - j});
}
if (e.size() > 2) {
cout << 0 << endl;
return;
}
if (e.size() == 2 && e[0].first != e[1].first ) {
int u1 = find(e[1].first, fa), v1 = find(e[0].first, fa);
int u2 = find(e[1].first + n, fa), v2 = find(e[0].first + n ,fa);
if (e[0].second == e[1].second) {
fa[u1] = v2;
fa[u2] = v1;
}
else {
fa[u1] = v1;
fa[u2] = v2;
}
}
}
ll cnt = 0;
for (int i = 0; i < n; i++) {
int u = find(i ,fa), v = find(i + n, fa);
if (fa[i] == i)cnt++;
if (fa[i + n] == i + n) cnt++;
if (u == v) {
cout << 0 << endl;
return;
}
}
cnt >>= 1;
cout << ksm(2, cnt) << endl;
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
4 4 4
result:
wrong answer 2nd numbers differ - expected: '0', found: '4'