QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666312 | #7900. Gifts from Knowledge | Foedere0 | WA | 15ms | 38608kb | C++20 | 1.9kb | 2024-10-22 17:45:29 | 2024-10-22 17:45:40 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int N = 1000010, mod = 1e9 + 7;
string s[N];
int a[N];
int p[N];
int find(int x)
{
if (p[x] != x)
p[x] = find(p[x]);
return p[x];
}
void solve()
{
int r, c;
cin >> r >> c;
for (int i = 1; i <= 2; i++)
{
p[i] = i;
}
for (int i = 1; i <= c; i++)
{
a[i] = 0;
}
for (int i = 1; i <= r; i++)
{
cin >> s[i];
s[i] = ' ' + s[i];
}
for (int i = 1; i <= c; i++)
{
for (int j = 1; j <= r; j++)
{
if (s[j][i] == '1')
{
a[i]++;
}
}
}
for (int i = 1; i <= c; i++)
{
if (a[i] + a[c - i + 1] > 2)
{
cout << 0 << endl;
return;
}
}
for (int i = 1; i <= c; i++)
{
if (a[i] + a[c - i + 1] == 2)
{
int x[3], cnt = 0;
for (int j = 1; j <= r; j++)
{
if (s[j][i] == '1')
{
x[++cnt] = j;
// cout << j << endl;
}
}
for (int j = 1; j <= r; j++)
{
if (s[j][c - i + 1] == '1')
{
x[++cnt] = j;
}
}
if (x[1] > x[2])
swap(x[1], x[2]);
int o = find(x[2]), pp = find(x[1]);
if (o != pp)
p[find(o)] = pp;
}
}
int res = 1;
for (int i = 1; i <= r; i++)
{
if (p[i] == i)
res = (res * 2) % mod;
}
cout << res << endl;
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 38608kb
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
Wrong Answer
time: 15ms
memory: 37832kb
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...
output:
4 4 2 4 4 4 4 4 4 2 4 4 4 4 4 4 4 4 4 2 4 2 4 4 4 4 4 4 4 4 4 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 4 4 4 2 4 4 4 4 4 2 4 4 4 4 4 4 4 4 4 4 4 4 2 4 2 4 4 4 4 4 4 2 4 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 4 4 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 4 4 4 4 4 4 4 4 4 4 4 4 4 ...
result:
wrong answer 1st numbers differ - expected: '1024', found: '4'