QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#631696 | #7900. Gifts from Knowledge | Pepinot | WA | 0ms | 3552kb | C++20 | 2.1kb | 2024-10-12 09:43:52 | 2024-10-12 09:43:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
const int maxn = 1e6 + 5, inf = 1e18, maxm = 4e4 + 5, base = 37;
const int N = 1e6;
const int mod = 1e9 + 7;
int n, m;
int a[maxn];
// string s;
struct Node{
int v, w;
};
struct DSU{
vector<int> fa;
DSU(int n) : fa(n) {
for(int i = 0; i < n; i++){
fa[i] = i;
}
}
int find(int x){
if(x == fa[x]) return fa[x];
fa[x] = find(fa[x]);
}
void merge(int x, int y){
if(find(x) != find(y)){
fa[find(x)] = find(y);
}
}
};
//long long ? maxn ? n? m?
void solve(){
int res = 0;
cin >> n >> m;
vector<vector<int>> a(n + 5, vector<int>(m + 5));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
char ch;
cin >> ch;
a[i][j] = ch - '0';
}
}
DSU d(2 * n + 5);
for(int j = 1; j <= m / 2; j++){
vector<int> vec[2];
for(int i = 1; i <= n; i++){
if(a[i][j]){
vec[0].pb(i);
}
if(a[i][m - j + 1]){
vec[1].pb(i);
}
}
if(vec[0].size() + vec[1].size() >= 3){
cout << 0 << '\n';
return;
}
for(int x = 0; x < 2; x++){
for(int y = 0; y < vec[x].size(); y++){
for(int z = y + 1; z < vec[x].size(); z++){
int u = vec[x][y], v = vec[x][z];
d.merge(u + n, v);
d.merge(u, v + n);
}
}
}
if(vec[0].size() && vec[1].size()){
int u = vec[0][0], v = vec[1][0];
d.merge(u, v);
d.merge(u + n, v + n);
}
}
if(m % 2 == 1){
int j = (m + 1) / 2;
vector<int> vec;
for(int i = 1; i <= n; i++){
if(a[i][j]){
vec.pb(i);
}
}
if(vec.size() >= 2){
cout << 0 << '\n';
return;
}
}
for(int i = 1; i <= n; i++){
if(d.find(i) == d.find(i + n)){
cout << 0 << '\n';
return;
}
}
int cnt = 0;
for(int i = 1; i <= 2 * n; i++){
if(d.find(i) == i) cnt++;
}
cnt /= 2;
res = 1;
for(int i = 1; i <= cnt; i++){
res = res * 2 % mod;
}
cout << res << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(9);
int T = 1;
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: 0ms
memory: 3552kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
1 0 1
result:
wrong answer 1st numbers differ - expected: '4', found: '1'