QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576803#9319. Bull FarmDBsoleilWA 128ms21612kbC++142.5kb2024-09-19 22:34:332024-09-19 22:34:33

Judging History

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

  • [2024-09-19 22:34:33]
  • 评测
  • 测评结果:WA
  • 用时:128ms
  • 内存:21612kb
  • [2024-09-19 22:34:33]
  • 提交

answer

#define pb push_back
#define fi first
#define se second
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

const int N=2005;
int T,n,L,q;
int p[N][N],pos[N],ans[N];
int ok[N][N],qu[N],hd,tl;
string s;
vector<int> ve[N];
struct qry{int x,y,p,id;};
vector<qry> qr[N];

int decode(char a,char b) {return (a-48)*50+(b-48);}

void input()
{
    cin>>n>>L>>q; cin.get();
    for(int i=1;i<=L;i++)
    {
        getline(cin,s);
        assert(s.length()==n*2);
        for(int j=1;j<=n;j++) p[i][j]=decode(s[j*2-2],s[j*2-1]);
    }
    for(int i=1,a,b,c;i<=q;i++)
    {
        getline(cin,s);
        assert(s.length()==6);
        a=decode(s[0],s[1]),b=decode(s[2],s[3]),c=decode(s[4],s[5]);
        qr[c].pb(qry{a,b,c,i});
        //cerr<<' '<<a<<' '<<b<<' '<<c<<' '<<i<<endl;
    }
}

void outpt()
{
    for(int i=1;i<=L;i++) 
    {
        cerr<<i<<endl;
        for(int j=1;j<=n;j++) cerr<<' '<<p[i][j];
        cerr<<endl;
        for(auto[a,b,c,d]:qr[i]) cerr<<' '<<a<<" "<<b<<' '<<c<<' '<<d<<endl;
    }
}

struct bingchaji
{
    int fa[N];
    void init(int n) {for(int i=1;i<=n;i++) fa[i]=i;}
    int findfa(int x) {return fa[x]==x?x:fa[x]=findfa(fa[x]);}
    bool merge(int x,int y)
    {
        int fx=findfa(x),fy=findfa(y);
        if(fx==fy) return 0;
        fa[fx]=fy; return 1;
    }
}bcj;

void ade(int x,int y) 
{
    if(ok[x][y]) return;
    ok[x][y]=1,ve[x].pb(y);
    qu[hd=tl=1]=y;
    while(hd<=tl)
    {
        int u=qu[hd++];
        for(int i=1;i<=n;i++) if(ok[i][x]) ok[i][u]=1;
        for(int v:ve[u]) if(!ok[x][v]) ok[x][v]=1,qu[++tl]=v;
    }
}

void modify(int*p)
{
    int cntp=0,k=-1;
    for(int i=1;i<=n;i++) pos[i]=0;
    for(int i=1;i<=n;i++) if(pos[p[i]]) cntp++,k=p[i]; else pos[p[i]]=i;
    if(cntp==0)
    {
        for(int i=1;i<=n;i++) if(bcj.merge(i,p[i])) ade(i,p[i]),ade(p[i],i);
    }
    if(cntp==1)
    {
        int x=pos[k],y,z;
        for(int i=1;i<=n;i++)
        {
            if(p[i]==k) y=i;
            if(!pos[i]) z=i;
        }
        ade(x,z),ade(y,z);
    }
}

void solve()
{
    input(),bcj.init(n);
    //outpt();
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ok[i][j]=0;
    for(int i=1;i<=n;i++) ok[i][i]=1;
    for(int t=0;t<=L;t++)
    {
        if(t>0) modify(p[t]);
        for(auto[a,b,c,d]:qr[t]) ans[d]=ok[a][b];
    }
    for(int i=1;i<=q;i++) cout<<ans[i];
    cout<<endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T--) solve();
}

詳細信息

Test #1:

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

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

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: 128ms
memory: 21612kb

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...1111111111111111101111111111111'