QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#565103#9319. Bull Farmsha7dowWA 68ms9288kbC++143.8kb2024-09-15 20:15:342024-09-15 20:15:34

Judging History

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

  • [2024-09-15 20:15:34]
  • 评测
  • 测评结果:WA
  • 用时:68ms
  • 内存:9288kb
  • [2024-09-15 20:15:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using PII = pair<int, int>;

constexpr int maxn = 2002;

string s;
int n, l, q;
array<int, maxn> c, fa, tp;
array<vector<int>, maxn> nxt, ext;
array<array<int, maxn>, maxn> t, e;

int find(int x) {
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}

int cur, top, cnt;
array<int, maxn> dfn, low, stk, vis, blk;
array<bitset<maxn>, maxn> to;

void tarjan(int u) {
    dfn[u] = low[u] = ++cur, stk[++top] = u, vis[u] = 1;
    for (int v : nxt[u])
        if (!dfn[v = find(v)])
            tarjan(v), low[u] = min(low[u], low[v]);
        else if (vis[v])
            low[u] = min(low[u], dfn[v]);
    if (dfn[u] == low[u] && ++cnt)
        do
            blk[stk[top]] = cnt, vis[stk[top]] = 0;
        while (stk[top--] != u);
    return;
}

struct node {
    int a, b, id;
};
array<int, maxn> ans;
array<vector<node>, maxn> p;

void solve() {
    cin >> n >> l >> q;
    for (int i = 1; i <= n; i++)
        fa[i] = i, nxt[i].clear();
    for (int i = 1; i <= l; i++)
        p[i].clear();
    for (int i = 1; i <= l; i++) {
        cin >> s;
        for (int j = 1, k = 0; j <= n; k += 2, j++)
            t[i][j] = (s[k] - 48) * 50 + (s[k + 1] - 48);
        for (int j = 0; j <= n; j++)
            c[j] = 0;
        for (int j = 1; j <= n; j++)
            c[0] += !c[t[i][j]]++;
        if (c[0] == n) {
            tp[i] = 1;
            for (int j = 1; j <= n; j++)
                e[i][j] = t[i][j];
        } else if (c[0] == n - 1) {
            tp[i] = 2;
            int from, to;
            for (int j = 1; j <= n; j++)
                if (!c[j])
                    to = j;
                else if (c[j] == 2)
                    from = j;
            for (int j = 1; j <= n; j++)
                if (t[i][j] == from)
                    e[i][j] = to;
                else
                    e[i][j] = 0;
        } else
            tp[i] = 0;
    }
    for (int i = 1; i <= q; i++) {
        cin >> s;
        int a = (s[0] - 48) * 50 + (s[1] - 48);
        int b = (s[2] - 48) * 50 + (s[3] - 48);
        int c = (s[4] - 48) * 50 + (s[5] - 48);
        p[c].push_back({a, b, i});
    }
    for (int i = 0; i <= l; i++) {
        if (tp[i] == 1) {
            for (int j = 1; j <= n; j++) {
                int x = find(j), y = find(e[i][j]);
                if (x != y) {
                    for (int k : nxt[x])
                        nxt[y].emplace_back(k);
                    fa[x] = y;
                }
            }
        } else if (tp[i] == 2) {
            for (int j = 1; j <= n; j++)
                if (e[i][j])
                    nxt[find(j)].emplace_back(e[i][j]);
        }
        cur = top = cnt = 0;
        for (int j = 1; j <= n; j++)
            dfn[j] = blk[j] = 0, ext[j].clear();
        for (int j = 1; j <= n; j++)
            if (find(j) == j && !dfn[j])
                tarjan(j);
        for (int j = 1; j <= n; j++)
            if (find(j) == j)
                for (int k : nxt[j])
                    if (blk[j] != blk[k = find(k)])
                        ext[blk[k]].emplace_back(blk[j]);
        for (int i = 1; i <= cnt; i++)
            to[i].reset(), to[i].set(i);
        for (int i = 1; i <= cnt; i++)
            for (int j : ext[i])
                to[j] |= to[i];
        for (auto [a, b, id] : p[i])
            ans[id] = to[blk[find(a)]].test(blk[find(b)]);
    }
    for (int i = 1; i <= q; i++)
        cout << ans[i];
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5932kb

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: 0
Accepted
time: 1ms
memory: 5984kb

input:

1
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202

output:

010101

result:

ok single line: '010101'

Test #3:

score: -100
Wrong Answer
time: 68ms
memory: 9288kb

input:

200
10 10 5000
01060:04020305080709
0103070:060204050908
09070503080401060:02
050308010204090:0607
03010502040607080:09
03080109020504060:07
06050:09040302080107
07080305010409060:02
030809010:0204060507
0:060908070201050304
060700
090:03
09080:
070405
010703
0:0100
080601
030600
070206
0:0:09
08040...

output:

011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...

result:

wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110001101101111111111111111...0101111111111111001111111111111'