QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#568121 | #9319. Bull Farm | awu | RE | 0ms | 7716kb | C++14 | 3.6kb | 2024-09-16 15:18:39 | 2024-09-16 15:18:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 N = 2010, M = 1e6 + 10;
i64 n, l, Q;
i64 g[N][N], p[N];
bool f[N][N];
struct node
{
i64 a, b, c, ans;
} q[M];
map<i64, vector<i64>> vec;
i64 get(char a, char b)
{
// i64 t = ((i64)a - 48) * 50 + ((i64)b - 48);
// cout << t << '\n';
return ((i64)a - 48) * 50 + ((i64)b - 48);
}
i64 find(i64 x)
{
if (p[x] != x)
p[x] = find(p[x]);
return p[x];
}
// 添加 a -> b
bool add(i64 a, i64 b)
{
if (!f[a][b])
{
// cout << a << " -> " << b << '\n';
// f[a][b] = true;
// for (i64 c = 1; c <= n; c++)
// {
// // 更新 a -> 其他点
// if (f[b][c])
// f[a][c] = true;
// // 更新 其他点 -> b
// if (f[c][a])
// f[c][b] = true;
// }
f[a][b] = true;
vector<i64> vec1;
vector<i64> vec2;
for (i64 u = 1; u <= n; u++)
if (f[u][a])
vec1.push_back(u);
for (i64 u = 1; u <= n; u++)
if (f[b][u])
vec2.push_back(b);
for (auto u : vec1)
for (auto v : vec2)
f[u][v] = true;
}
}
void solve()
{
cin >> n >> l >> Q;
for (i64 i = 0; i <= n; i++)
{
p[i] = i;
for (i64 j = 0; j <= n; j++)
f[i][j] = false;
f[i][i] = true;
}
for (i64 i = 0; i <= l; i++)
vec[i].clear();
for (i64 i = 1; i <= l; i++)
for (i64 j = 1; j <= n; j++)
{
char a, b;
cin >> a >> b;
g[i][j] = get(a, b);
}
for (i64 i = 1; i <= Q; i++)
{
char ch1, ch2;
cin >> ch1 >> ch2;
q[i].a = get(ch1, ch2);
cin >> ch1 >> ch2;
q[i].b = get(ch1, ch2);
cin >> ch1 >> ch2;
q[i].c = get(ch1, ch2);
vec[q[i].c].push_back(i);
}
for (i64 i = 0; i <= l; i++)
{
set<i64> S;
for (i64 j = 1; j <= n; j++)
S.insert(g[i][j]);
if (S.size() == n)
{
map<i64, i64> mp;
for (i64 j = 1; j <= n; j++)
if (!mp[j])
{
for (i64 k = g[i][j]; k != j; k = g[i][k])
{
mp[k] = true;
i64 a = find(j), b = find(k);
if (a != b)
{
p[b] = a;
}
}
}
}
else if (S.size() == n - 1)
{
i64 t = 1;
while (S.count(t))
t++;
map<i64, i64> mp;
for (i64 j = 1; j <= n; j++)
{
if (mp.count(g[i][j]))
{
add(find(mp[g[i][j]]), find(t));
add(find(j), find(t));
break;
}
mp[g[i][j]] = j;
}
}
for (i64 u : vec[i])
{
// cout << "i: " << i << " u: " << u << '\n';
// cout << "a: " << q[u].a << " b: " << q[u].b << '\n';
q[u].ans = f[find(q[u].a)][find(q[u].b)];
}
}
for (i64 i = 1; i <= Q; i++)
cout << q[i].ans;
cout << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
i64 T = 1;
cin >> T;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7716kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202