QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567873 | #9319. Bull Farm | awu | WA | 1ms | 5680kb | C++14 | 2.6kb | 2024-09-16 14:24:38 | 2024-09-16 14:24:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 N = 2010;
i64 n, l, Q;
i64 g[N][N];
bool f[N][N];
struct node
{
i64 a, b, c, ans;
} q[N];
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);
}
// 添加 a -> b
void work(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;
}
}
}
void solve()
{
cin >> n >> l >> Q;
for (i64 i = 0; i <= n; i++)
{
for (i64 j = 0; j <= n; j++)
f[i][j] = false;
f[i][i] = true;
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)
{
for (i64 j = 1; j <= n; j++)
{
work(j, g[i][j]);
work(g[i][j], j);
}
}
else if (S.size() == n - 1)
{
map<i64, i64> mp;
for (i64 j = 1; j <= n; j++)
{
if (mp.count(g[i][j]))
{
work(mp[g[i][j]], g[i][j]);
work(j, g[i][j]);
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[q[u].a][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: 1ms
memory: 5680kb
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
Wrong Answer
time: 0ms
memory: 5680kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
000110
result:
wrong answer 1st lines differ - expected: '010101', found: '000110'