QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#565758 | #9319. Bull Farm | LiZiqing | WA | 0ms | 5900kb | C++20 | 2.0kb | 2024-09-15 22:10:24 | 2024-09-15 22:10:24 |
Judging History
answer
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2005;
ll n, l, q, cnt;
ll vis[N][N];
ll t[N][N], ans[N];
bool tf[N];
bool dfs(int u, int i, vector<int>& f, map<ll, ll>& mp, int& head, int& gc)
{
tf[u] = 1;
int v = t[i][u];
if (tf[v]) return false;
if (f[v])
{
gc = ++cnt;
head = v;
return true;
}
else
{
if (!dfs(v, i, f, mp, head, gc))
return false;
}
if (u == head) return false;
vis[i][u] = gc;
if (vis[i - 1][u] != 0)
mp[vis[i - 1][u]] = gc;
return true;
}
ll read()
{
char x, y; cin >> x >> y;
return (x - 48) * 50 + (y - 48);
}
void solve()
{
cin >> n >> l >> q;
for (int i = 1; i <= l; ++i)
{
cnt = 0;
for (int j = 1; j <= n; ++j)
{
vis[i][j] = 0;
t[i][j] = read();
tf[j] = 0;
}
map<ll, ll> mp;
for (int j = 1; j <= n; ++j)
{
if (!tf[j])
{
vector<int> f(n+10, 0);
int head = 0, gc = 0;
dfs(j, i, f, mp, head, gc);
}
}
for (int j = 1; j <= n; ++j)
{
if (vis[i - 1][j] == 0) continue;
if (mp[vis[i - 1][j]] == 0)
{
mp[vis[i - 1][j]] = ++cnt;
}
vis[i][j] = mp[vis[i - 1][j]];
}
}
for (int i = 1; i <= q; ++i)
{
ll a = read(), b = read(), c = read();
if (c > l) c = l;
if (vis[c][a]!=0 && vis[c][b] != 0 && vis[c][a] == vis[c][b])
ans[i] = 1;
else
ans[i] = 0;
}
for (int i = 1; i <= n; ++i)
cout << ans[i];
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5900kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
00000 000000
result:
wrong answer 1st lines differ - expected: '1011', found: '00000'