QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508860 | #7900. Gifts from Knowledge | Welcome24ever | RE | 0ms | 3612kb | C++23 | 4.0kb | 2024-08-07 20:50:23 | 2024-08-07 20:50:24 |
Judging History
answer
// __ __ ___ ___ __ __
// /\ \ __/\ \ /\_ \ /'___'\ /\ \ \
// \ \ \/\ \ \ \ __\//\ \ ___ ___ ___ ___ __ /\_\ /\ \ \ \ \ __ __ __ __ _ __
// \ \ \ \ \ \ \ /'__'\ \ \ /'___\ / __'\ /' __' __'\ /'__'\/_/// /__\ \ \ \_ /'__'\/\ \/\ \ /'__'\/\''__\
// \ \ \_/ \_\ \/\ __/ \_\ \_/\ \__//\ \L\ \/\ \/\ \/\ \/\ __/ // /_\ \ \__ ,__\/\ __/\ \ \_/ |/\ __/\ \ \/
// \ '\___x___/\ \____\/\____\ \____\ \____/\ \_\ \_\ \_\ \____\/\______/ \/_/\_\_/\ \____\ \___/ \ \____\ \_\
// '\/__//__/ \/____/\/____/\/____/\/___/ \/_/\/_/\/_/\/____/\/_____/ \/_/ \/____/ \/__/ \/____/ \/_/
// bilibili:24Records
// link:https://space.bilibili.com/3546387113314828
// blog link:https://welcome24ever.github.io/24Records/
//
// Then,we just singing like.
// Welcome To Forever.
#include "bits/stdc++.h"
using namespace std;
const int Welcome24ever = 0;
#define endl '\n'
#define fixset(x) fixed << setprecision(x)
//#define int long long
typedef long long ll; typedef pair<int,int> PII;
long double pi = acos(-1);
const int MOD = 1e9 + 7; const int N = 2e5+10;
void NeverSayNever() {
int n, m;
cin >> n >> m;
vector<string> mp(n + 1);
for (int i = 1; i <= n; i++) {
string str;
cin >> str;
mp[i] = ' ' + str;
}
vector<vector<int>> one(m + 2);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (mp[i][j] == '1') {
one[j].push_back(i);
}
}
}
if (m % 2 == 1) {
if (one[m / 2 + 1].size() > 1) {
cout << 0 << endl;
return;
}
}
vector<vector<int>> adj(n * 3);
for (int i = 1; i <= n; ++i) {
adj[i].push_back(i + n);
adj[i + n].push_back(i);
}
bool flag = false;
for (int i = 1; i <= m / 2; ++i) {
int cnt = one[i].size() + one[m - i + 1].size();
if (cnt > 2) {
flag = true;
break;
}
if (cnt < 2) {
continue;
}
if (one[i].size() == 1) {
int cur = one[i][0];
int nxt = one[m - i + 1][0];
if (cur == nxt) continue;
adj[cur].push_back(nxt + n);
adj[nxt + n].push_back(cur + n);
adj[nxt].push_back(cur + n);
adj[cur + n].push_back(nxt);
} else {
int cur, nxt;
if (one[i].size() != 0) {
cur = one[i][0];
nxt = one[i][1];
} else {
cur = one[m - i + 1][0];
nxt = one[m - i + 1][1];
}
adj[cur].push_back(nxt);
adj[nxt].push_back(cur);
adj[cur + n].push_back(nxt + n);
adj[nxt + n].push_back(cur + n);
}
}
if (flag) {
cout << 0 << endl;
return;
}
int ans = 1;
vector<int> vis(n + 1, 0);
auto dfs = [&](auto &&self, int cur, int fa) -> bool {
for (auto &nxt: adj[cur]) {
if (vis[cur] == vis[nxt]) {
return false;
}
if (vis[nxt] || nxt == fa) {
continue;
}
if (vis[cur] == 1) {
vis[nxt] = 2;
} else {
vis[nxt] = 1;
}
if (self(self, nxt, cur) == false) {
return false;
}
}
return true;
};
for (int i = 1; i <= 2 * n; i++) {
if (vis[i] != 0) {
continue;
}
vis[i] = 1;
bool f =dfs(dfs, i, i);
if (f) {
ans = ans * 2 % MOD;
} else {
ans = 0;
}
}
cout << ans << endl;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
NeverSayNever();
}
return Welcome24ever;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
4 0 2
result:
ok 3 number(s): "4 0 2"
Test #2:
score: -100
Runtime Error
input:
15613 10 10 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 15 8 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 1 5 00000 5 9 000000000 000000000 0000...