QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571014#9319. Bull FarmBrokenSegmentWA 0ms3592kbC++202.7kb2024-09-17 19:51:322024-09-17 19:51:33

Judging History

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

  • [2024-09-17 19:51:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-09-17 19:51:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<long long,long long>
#define eb emplace_back

void solve()
{
    int n,l,q;cin>>n>>l>>q;
    //冰茶几
    vector<int>f(n+1);
    iota(f.begin(),f.end(),0);
    function<int(int)> find = [&](int x) {
        return x==f[x]?x:f[x]=find(f[x]);
    };
    auto merge =[&](int x,int y) {
        int fx=find(x),fy=find(y);
        if(fx==fy) return false;
        f[fx]=fy;
        return true;
    };
    //
    //dij
    vector e(n+1,vector<pair<int,int>>(n+1));
    vector dis(n+1,vector<int>(n+1,(int)1e9)),vis(n+1,vector<int>(n+1));
    auto dij = [&](int s) { 
        priority_queue<pii,vector<pii>,greater<pii>>q;
        dis[s][s]=0;
        q.emplace(0,s);
        while(!q.empty()) {
            auto [_,u] = q.top();q.pop();
            if(vis[s][u]) continue;
            vis[s][u]=1;
            for(auto [v,w]:e[u]) {
                if(dis[s][v]>max(dis[s][u],w)) {
                    dis[s][v]=max(dis[s][u],w);
                    q.emplace(dis[s][v],v);
                }
            }
        }
    };
    //
    auto get = [&]() {
        char a,b;
        cin>>a>>b;
        return 50*(a-48) + b-48;
    };
    vector<int>p(n+1);
    for(int i=1;i<=l;i++) {
        vector<int>cnt(n+1,0);
        for(int j=1;j<=n;j++) {
            p[j]=get();
            cnt[p[j]]++;
        }
        bool ok=1;int two=-1,zero=-1;
        for(int j=1;j<=n;j++) {
            if(cnt[j]==2) {
                if(two==-1) {
                    two = j;
                }else {
                    ok=0;
                    break;
                }
            }else 
            if(cnt[j]==0) {
                if(zero==-1) {
                    zero=j;
                }else {
                    ok=0;
                    break;
                }
            } else if(cnt[j]!=1) break;
        }
        if(!ok) continue;
        if(two!=-1) {
            for(int j=1;j<=n;j++)
                if(cnt[p[j]]==2) {
                    e[j].emplace_back(zero,i);
                }
        }else {
            // for(int i=1;i<=n;i++)
            //     cerr<<p[i]<<" \n"[i==n];
            for(int j=1;j<=n;j++) 
                if(merge(j,p[j])) {
                    e[j].emplace_back(p[j],i);
                    e[p[j]].emplace_back(j,i);
                }
        }
    }
    for(int i=1;i<=n;i++)
        dij(i);
    while(q--) {
        int a,b,c;a=get(),b=get(),c=get();
        cout<<(dis[a][b]<=c?1:0);
    }
    cout<<"\n";
}
main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cerr.tie(0);
    int _=1;cin>>_;
    for(int i=1;i<=_;i++) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

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: 3532kb

input:

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

output:

111111

result:

wrong answer 1st lines differ - expected: '010101', found: '111111'