QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611791#9319. Bull FarmDE_aemmprtyWA 163ms7924kbC++173.8kb2024-10-04 22:47:062024-10-04 22:47:07

Judging History

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

  • [2024-10-04 22:47:07]
  • 评测
  • 测评结果:WA
  • 用时:163ms
  • 内存:7924kb
  • [2024-10-04 22:47:06]
  • 提交

answer

/*******************************
| Author:  DE_aemmprty
| Problem: Bull Farm
| Contest: Virtual Judge - QOJ
| URL:     https://vjudge.net/problem/QOJ-9319
| When:    2024-10-04 22:25:30
| 
| Memory:  1014 MB
| Time:    5000 ms
*******************************/
#include <bits/stdc++.h>
using namespace std;

long long read() {
    char c = getchar();
    long long x = 0, p = 1;
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') p = -1, c = getchar();
    while (c >= '0' && c <= '9')
        x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return x * p;
}

const int N = 2007;
const int M = 1e6 + 7;

struct Ans {
    long long t, c, id;
};

int n, l, q;
vector <Ans> qry[N];
int wjc[N][N], len[N];
long long dis[N];
bool vis[N];
vector <pair <int, int> > to[N];
int fa[N], ans[M];
int cnt[N];
int a[N][N];

void init() { for (int i = 1; i <= n; i ++) fa[i] = i;}
int find(int x) { return x == fa[x] ? x : (fa[x] = find(fa[x]));}
int chger(char c1, char c2) { return (c1 - 48) * 50 + c2 - 48;}

void solve() {
    n = read(), l = read(), q = read();
    init();
    for (int i = 1; i <= n; i ++) {
        to[i].clear();
        qry[i].clear();
        ans[i] = 0;
    }
    for (int i = 1; i <= l; i ++) {
        string s;
        cin >> s;
        int m = (int) s.size(), num = 0, ch[2] = {0, 0};
        for (int j = 1; j <= n; j ++)
            cnt[j] = 0;
        s = " " + s;
        for (int j = 1; j <= m; j += 2) {
            int x = chger(s[j], s[j + 1]);
            if (cnt[x] > 0) {
                ch[0] = cnt[x];
                ch[1] = j;
            } else if (cnt[x] == 0) {
                cnt[x] = j;
                num ++;
            }
            a[i][(j + 1) / 2] = x;
            // printf("%d ", x);
        }
        // cout << '\n';
        int sp = 0;
        for (int j = 1; j <= n; j ++)
            if (!cnt[j]) sp = j;
        if (num == n - 1) {
            to[ch[0]].push_back({sp, i});
            to[ch[1]].push_back({sp, i});
        } else if (num == n) {
            for (int j = 1; j <= n; j ++) {
                if (find(j) != find(a[i][j])) {
                    fa[find(j)] = find(a[i][j]);
                    to[j].push_back({a[i][j], i});
                    to[a[i][j]].push_back({j, i});
                    // printf("%d and %d add double edge\n", j, a[i][j]);
                }
            }
        }
    }
    for (int i = 1; i <= q; i ++) {
        string sx; cin >> sx; sx = " " + sx;
        int s = chger(sx[1], sx[2]);
        int t = chger(sx[3], sx[4]);
        int c = chger(sx[5], sx[6]);
        // printf("(s, t, c) = (%d, %d, %d)\n", s, t, c);
        qry[s].push_back({t, c, i});
    }
    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= n; j ++) {
            dis[j] = 2e18;
            vis[j] = 0;
        }
        for (int j = 0; j <= l; j ++)
            len[j] = 0;
        dis[i] = 0;
        wjc[0][++ len[0]] = i;
        for (int d = 0; d <= l; d ++) {
            for (int j = 1; j <= len[d]; j ++) {
                int u = wjc[d][j];
                if (vis[u]) continue;
                vis[u] = 1;
                for (auto v : to[u])
                    if (dis[v.first] > max(d, v.second)) {
                        dis[v.first] = max(d, v.second);
                        wjc[dis[v.first]][++ len[dis[v.first]]] = v.first;
                    }
            }
        }
        // printf("start in %d : ", i);
        // for (int j = 1; j <= n; j ++)
        //     cout << dis[j] << ' '; cout << '\n';
        for (auto qx : qry[i])
            if (dis[qx.t] <= qx.c)
                ans[qx.id] = 1;
    }
    for (int i = 1; i <= q; i ++)
        cout << ans[i];
    cout << '\n';
}

signed main() {
    int t = read();
    while (t --) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 7744kb

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: 163ms
memory: 7868kb

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 2nd lines differ - expected: '111111011101111011011111111111...1111110111111110111011110101111', found: '111111011101111111111111111111...1111111111111111111111111111111'