QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#656917 | #7900. Gifts from Knowledge | Rezhou | WA | 15ms | 3752kb | C++23 | 5.2kb | 2024-10-19 13:51:37 | 2024-10-19 13:51:37 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
#define double long double
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef const double* (*p_fun)(const double*, int);
const LL N = 1e5 + 10, M = 5e3 + 10, mod = 1e9 + 7, LLF = 1e13, null = 0x3f3f3f3f3f3f3f;
template <typename T> bool chmax(T& a, const T& b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <typename T, typename... Args> bool chmax(T& a, const T& b, const Args &...args)
{
bool updated = chmax(a, b);
return chmax(a, args...) || updated;
}
template <typename T> bool chmin(T& a, const T& b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T, typename... Args> bool chmin(T& a, const T& b, const Args &...args)
{
bool updated = chmin(a, b);
return chmin(a, args...) || updated;
}
class UnionFind
{
public:
vector<int> parent;
vector<int> size;
int n;
// 当前连通分量数目
int setCount;
public:
UnionFind(int _n) : n(_n), setCount(_n), parent(_n), size(_n, 1)
{
iota(parent.begin(), parent.end(), 0);
}
int find(int x)
{
return parent[x] == x ? x : parent[x] = find(parent[x]);
}
bool merge(int x, int y)
{
x = find(x);
y = find(y);
if (x == y)
return false;
if (size[x] < size[y])
swap(x, y);
parent[y] = x;
size[x] += size[y];
--setCount;
return true;
}
bool connected(int x, int y)
{
x = find(x);
y = find(y);
return x == y;
}
};
int qmi(int a, int b)
{
int res = 1;
a %= mod;
while (b)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int sqrt(int x)
{
int l = 0, r = 3e9; // LLONG_MAX
while (l < r)
{
int mid = (l + r + 1) >> 1;
if (mid * mid > x)
r = mid - 1; // 向下取整
else
l = mid;
}
return r;
}
int get(int x)
{
int res = 0;
while (x)
{
chmax(res, x % 10);
x /= 10;
}
return res;
}
bool check(vector<char>& v)
{
int mid = v.size() / 2;
if (v.back() != v.front())
return 0;
int l = 1, r = v.size() - 2;
while (l < r)
{
if (v[l] == v[l - 1] || v[l] != v[r])
return 0;
l++, r--;
}
return 1;
}
int p[N], d[N];
int find(int x)
{
if (p[x] != x)
{
int u = find(p[x]);
d[x] += d[p[x]];
p[x] = u;
}
return p[x];
}
static inline void solve()
{
int c, r;
cin >> c >> r;
vector<string> v(c + 1);
for (int i = 1; i <= r; i++)
p[i] = i, d[i] = 0;
for (int i = 1; i <= c; i++)
cin >> v[i];
vector<int> lock(r);
vector<vector<pii>> f(r);
bool flag = 0;
for (int i = 0; i < r; i++)
{
for (int j = 1; j <= c; j++)
{
bool flag1 = 0, flag2 = 0;
if (v[j][i] == '1')
{
flag1 = 1;
if (f[i].size())
{
for (auto [y, op] : f[i])
{
int x = j;
int px = find(x), py = find(y);
if (px == py && ((d[x] - d[y]) % 2 + 2) % 2 != op)
flag = 1;
else if (px != py)
{
p[px] = py;
d[px] = ((d[y] - d[x] + op) % 2 + 2) % 2;
}
}
}
}
if (v[j][r - i - 1] == '1')
{
if (f[i].size())
{
flag2 = 1;
for (auto [y, op] : f[i])
{
op++;
op %= 2;
int x = j;
int px = find(x), py = find(y);
if (px == py && ((d[x] - d[y]) % 2 + 2) % 2 != op)
flag = 1;
else if (px != py)
{
p[px] = py;
d[px] = ((d[y] - d[x] + op) % 2 + 2) % 2;
}
}
}
}
if (flag1)
f[i].push_back({ j, 0 });
if (flag2)
f[i].push_back({ j, 1 });
}
}
vector<int> vis(c + 1);
int ans = 0;
for (int i = 1; i <= c; i++)
{
int x = find(i);
if (!vis[x])
vis[x] = 1, ans++;
}
if (flag)
{
cout << 0 << "\n";
return;
}
cout << qmi(2, ans) << "\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << unitbuf;
int t = 1;
cin >> t;
while (t--)
{
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
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: 3752kb
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:
1024 2048 2 32 2048 128 32 16 16 2 16384 16384 128 128 32768 8192 128 64 16384 2 4 2 4096 16 4096 1024 32768 32768 16384 8 128 2 16 4096 8192 32768 8192 8192 16 16384 16384 256 128 8 256 8 4096 512 2 4 32 32 2 64 512 1024 32768 32768 2 64 16384 16 8192 16 256 16 64 8192 8192 64 1024 2 32768 2 4 512 ...
result:
wrong answer 2nd numbers differ - expected: '32768', found: '2048'