QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#654773 | #7900. Gifts from Knowledge | LurkInShadow | WA | 0ms | 3572kb | C++17 | 3.1kb | 2024-10-18 22:08:19 | 2024-10-18 22:08:20 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define ls u << 1
#define rs u << 1 | 1
#define ff first
#define ss second
#define pb push_back
#define p_q priority_queue
#define INF 0x7FFFFFFF
#define INFF 9223372036854775807
#define den(a) cout << #a << " = " << a << "\n";
#define deg(a) cout << #a << " = " << a << " ";
using namespace std;
using TIII = tuple<int,int,int>;
using PII = pair<int, int>;
using ULL = unsigned long long;
using ld = long double;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e6 + 10;
int fa[2 * N],n,m;
vector<string> g;
int find(int x)
{
if(fa[x] == x) return fa[x];
return fa[x] = find(fa[x]);
}
void unionn(int u,int v)
{
int x = find(u),y = find(v);
if(x == y) return;
fa[y] = x;
}
int qpow(int base,int power)
{
int res = 1;
while(power)
{
if(power & 1) res = res * base % MOD;
power >>= 1;
base = base * base % MOD;
}
return res;
}
void solve()
{
cin >> n >> m;
g.clear();
for(int i = 1;i <= 2 * n;i ++) fa[i] = i;
for(int i = 0;i < n;i ++)
{
string s;
cin >> s;
g.pb(s);
}
int sc = 0;
for(int i = 0;i < m;i ++)
{
int c = 0;
for(int j = 0;j < n;j ++)
{
if(g[j][i] == '1') c ++;
}
if(c > 2)
{
cout << 0 << '\n';
return;
}
sc += c;
if(sc > m)
{
cout << 0 << '\n';
return;
}
}
for(int i = 0,j = m - 1;i < j;i ++,j --)
{
vector<int> L,R;
for(int k = 0;k < n;k ++)
{
if(g[k][i] == '1') L.pb(k);
if(g[k][j] == '1') R.pb(k);
}
if(L.size() + R.size() > 2)
{
cout << 0 << '\n';
return;
}
if(L.size() == 2)
{
unionn(L[0],L[1] + n);
unionn(L[1],L[0] + n);
}
else if(R.size() == 2)
{
unionn(R[0],R[1] + n);
unionn(R[1],R[0] + n);
}
// else
// {
// unionn(L[0],R[0]);
// unionn(L[0] + n,R[0] + n);
// }
}
int cnt = 0;
for(int i = 0;i < 2 * n;i ++)
{
if(fa[i] == i) cnt ++;
}
cout << qpow(2,cnt / 2) << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
/*
/\7 ∠_/
/ │ / /
│ Z _,< / /`ヽ
│ ヽ / 〉
Y ` / /
イ● 、 ● ⊂⊃〈 /
() へ | \〈
>ー 、_ ィ │ //
/ へ / ノ<| \\
ヽ_ノ (_/ │//
7 |/
>―r ̄ ̄`ー―_
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3572kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
8 0 2
result:
wrong answer 1st numbers differ - expected: '4', found: '8'