QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#565573#9319. Bull FarmcaidzhWA 189ms112588kbC++144.0kb2024-09-15 21:43:272024-09-15 21:43:29

Judging History

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

  • [2024-09-15 21:43:29]
  • 评测
  • 测评结果:WA
  • 用时:189ms
  • 内存:112588kb
  • [2024-09-15 21:43:27]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=head[a];i;i=e[i].nxt)
using namespace std;
const int M=8005,Q=1e6+5;

int n,m,q,a[M][M],ans[Q],fl[M];
bool mk[M][M];
char s[M];
struct node{
    int a,b,c,id;
    bool operator < (const node &_)const{
        return c<_.c;
    }
}b[Q];

int d[M];

bitset<M> g[M];

int head[M],cnte,N,fa[M];
bool die[M];
struct edge{int to,nxt;}e[M*M];
void Add(int x,int y){
    e[++cnte]=(edge){y,head[x]};
    head[x]=cnte;
}
int FA(int x){return fa[x]==x?x:fa[x]=FA(fa[x]);}

queue<int> que;
vector<int> E[M],TMP;

int dfn[M],low[M],tot,inst[M],st[M],top;

void COPY(int x,int r){
    erep(i,x){
        int y=e[i].to;
        y=FA(y);
        if(y==r)continue;
        Add(r,y);
    }
    g[r]|=g[x];
}
void dfs(int x){
    dfn[x]=low[x]=++tot;
    inst[st[++top]=x]=1;
    erep(i,x){
        int y=e[i].to;
        if(!dfn[y])dfs(y),low[x]=min(low[x],low[y]);
        else if(inst[y])low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x]){
        int y;
        ++N;fa[N]=N;
        if(N>4010){
            cout<<"fuck\n";
            exit(0);
        }
        g[N][N]=1;
        TMP.clear();
        while(inst[x]){
            y=st[top--];
            fa[y]=N;
            inst[y]=0;
            TMP.pb(y);
        }
        rep(i,0,TMP.size()-1)COPY(TMP[i],N);
    }
}
void ADD(int p){
    if(fl[p]==0)return;
    rep(i,1,n)if(mk[p][i]){
        int x=FA(i);
        int y=FA(a[p][i]);
        if(x!=y)Add(x,y);
    }
    rep(i,1,N)dfn[i]=0;
    rep(i,1,N)inst[i]=0;
    tot=top=0;
    rep(x,1,N)if(!die[x] && !dfn[x])dfs(x);

    rep(i,1,N)if(fa[i]!=i)die[i]=1;
    rep(x,1,N)E[x].clear();
    rep(x,1,N)d[x]=0;
    rep(x,1,N)if(!die[x]){
        erep(i,x){
            int y=FA(e[i].to);
            if(x==y)continue;
            E[y].pb(x);++d[x];
        }
    }
    rep(x,1,N)head[x]=0;cnte=0;
    rep(x,1,N)if(!die[x]){
        rep(i,0,E[x].size()-1){
            int y=E[x][i];y=FA(y);
            if(y==x)continue;
            Add(y,x);
        }
    }
    // rep(x,1,N)if(!die[x])printf("%d :%d\n",x,d[x]);
    // printf("p %d N %d\n",p,N);
    rep(x,1,N)if(!die[x] && !d[x])que.push(x);
    while(!que.empty()){
        int x=que.front();que.pop();
        erep(i,x){
            int y=e[i].to;
            y=FA(y);
            g[x]|=g[y];
        }
        rep(i,0,E[x].size()-1){
            int y=E[x][i];
            y=FA(y);
            --d[y];
            if(!d[y])que.push(y);
        }
    }
    return;
}
void solve(){
    scanf("%d%d%d",&n,&m,&q);
    rep(i,1,m){
        scanf("%s",s+1);
        rep(j,1,n)a[i][j]=(s[j*2-1]-48)*50+(s[j*2]-48);
    }
    rep(i,1,m){
        rep(j,1,n)d[j]=0;
        int tmp=0;
        rep(j,1,n){
            ++d[a[i][j]];
            if(d[a[i][j]]>1)++tmp;
        }
        fl[i]=0;
        if(tmp>1)continue;
        if(tmp==1){
            int pos=0;
            rep(j,1,n)if(d[j]==0)pos=j;
            rep(j,1,n)if(d[a[i][j]]>1)mk[i][j]=1,a[i][j]=pos;
            fl[i]=1;
        }
        else{
            rep(j,1,n)mk[i][j]=1;
            fl[i]=2;
        }
    }
    rep(i,1,q){
        scanf("%s",s+1);
        b[i].a=(s[1]-48)*50+(s[2]-48);
        b[i].b=(s[3]-48)*50+(s[4]-48);
        b[i].c=(s[5]-48)*50+(s[6]-48);
        b[i].id=i;
    }
    sort(b+1,b+q+1);
    int lst=0;
    N=n;
    rep(i,1,n)g[i][i]=1;
    rep(i,1,n)fa[i]=i;

    rep(i,1,q){
        while(lst<b[i].c)ADD(++lst);
        // printf("%d: %d -> %d\n",b[i].id,FA(b[i].a),FA(b[i].b));
        ans[b[i].id]=g[FA(b[i].a)][FA(b[i].b)];
    }
    rep(i,1,q)printf("%d",ans[i]);puts("");
}
void clear(){
    rep(i,1,m)fl[i]=0;
    rep(i,1,m)rep(j,1,n)mk[i][j]=0;
    rep(i,1,N)g[i].reset();
    rep(i,1,N)die[i]=0;
    rep(i,1,N)head[i]=0;
    cnte=0;
}
int main(){
    int t;scanf("%d",&t);
    while(t--)clear(),solve();
    return 0;
}

详细

Test #1:

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

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: 2ms
memory: 12512kb

input:

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

output:

010101

result:

ok single line: '010101'

Test #3:

score: 0
Accepted
time: 96ms
memory: 12252kb

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:

ok 200 lines

Test #4:

score: 0
Accepted
time: 91ms
memory: 33412kb

input:

1
2000 1 1000000
M=:]A@8UAY7W2JJ4KEHIA[HSCQ1ENSC`JXR;F3PJ:_@41P9Z=9HR8P<<:DUXRR9^WOQFL?NZP6S@=J0^WE32=6;\U0?88]Q_RNPUMT6YU<4<S]H?:7OCQYOT4YAV1^764ENWSDBED>M7A:BI>KSIR48JQ9B=N\5T3N4A2aF0@>3TI81<G7;YE>W`NMP<:IT4CI3D0=GZC3I\CLQJQBA9BDIS9SAM55KaVA<Z@D=>:Y?CQHUQ5U3a6UVI8OKX9_FAF^7=5M85;<0;8YPAM<7Z7PP7A=N...

output:

000101000101100010001000000010010110000001000001001100000000010000100001000000101100000000010000001000000001110000010110100000111100100000001000000000011001010001000001001000100000000100011001100110010000010000101100000011111000000010000101010010000000010101000001010111100000100000000000000101000100...

result:

ok single line: '000101000101100010001000000010...0101000101000000000010101001000'

Test #5:

score: 0
Accepted
time: 189ms
memory: 112588kb

input:

1
2000 2000 1000000
FVAaH7GRPO;_11Da5J18@3SMG==\G8E8S^6:M4L0JH>MN5IXT>2<7WJ3U8LVJS=;;3F13>0D0>VOIIU@EPHG6ABL6;K?T1PXDERLG07]5C9^GDKG<SBMIW;`4W8P3=469TIPKH0O34523_J5C2MJ17D25Z@=K8H@M>WK<CMK7EO]BPD7B6AW741J5YIHIa1:ERSG>L3N2^F3<4F`DLE@2AA5=8GZK6:192FB736[WMV7:^DA2C:<LK040VJBM3M]WXU50`407TR_?PLF@5VL7OSL...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok single line: '111111111111111111111111111111...1111111111111111111111111111111'

Test #6:

score: -100
Wrong Answer
time: 104ms
memory: 112284kb

input:

1
2000 2000 1000000
0102030405060708090:0;0<0=0>0?0@0A0B0C0D0E0F0G0H0I0J0K0L0M0N0O0P0Q0R0S0T0U0V0W0X0Y0Z0[0\0]0^0_0`0a101112131415161718191:1;1<1=1>1?1@1A1B1C1D1E1F1G1H1I1J1K1L1M1N1O1P1Q1R1S1T1U1V1W1X1Y1Z1[1\1]1^1_1`1a202122232425262728292:2;2<2=2>2?2@2A2B2C2D2E2F2G2H2I2J2K2L2M2N2O2P2Q2R2S2T2U2V2W2X...

output:

fuck

result:

wrong answer 1st lines differ - expected: '000000000000000000000000000000...0000000000000000000000000000000', found: 'fuck'