QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#565758#9319. Bull FarmLiZiqingWA 0ms5900kbC++202.0kb2024-09-15 22:10:242024-09-15 22:10:24

Judging History

你现在查看的是最新测评结果

  • [2024-09-15 22:10:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5900kb
  • [2024-09-15 22:10:24]
  • 提交

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'