QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#578328 | #9319. Bull Farm | Yoralen | WA | 84ms | 21968kb | C++14 | 1.9kb | 2024-09-20 18:17:54 | 2024-09-20 18:17:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2005,M=2000005;
bitset<N>f[N];char s[N];
int Te,rd[N],ans[M];
int cnt=0,h[N],vis[N],flg,I0,I2,n,m,Q,t[N][N];
struct Edge{int to,next;}w[N<<2];
struct node{int x,y,i;};
vector<node>G[N];
void Add(int u,int v){
if(f[u][v])return;
for(int i=1;i<=n;i++){if(f[i][u])f[i]|=f[v];}
}
void Ad(int u,int v){
rd[v]++;
w[++cnt].to=v,w[cnt].next=h[u],h[u]=cnt;
w[++cnt].to=u,w[cnt].next=h[v],h[v]=cnt;
}
void DFS(int u){
vis[u]=1;
if(rd[u]==0){if(!I0)I0=u;else flg=1;}
else if(rd[u]==2){if(!I2)I2=u;else flg=1;}
else if(rd[u]!=1)flg=1;
for(int i=h[u];i;i=w[i].next){
int e=w[i].to;
if(!vis[e])DFS(e);
}
}
int main(){
int i,x,y,z,I,j,k;
scanf("%d",&Te);
while(Te--){
scanf("%d%d%d",&n,&m,&Q);
for(i=1;i<=n;i++)f[i].reset(),f[i][i]=1;
for(i=1;i<=m;i++)G[i].clear();
for(i=1;i<=m;i++){
scanf("%s",s+1);
for(j=1,k=1;j<=n+n;j+=2,k++)
t[i][k]=(s[j]-'0')*50+(s[j+1]-'0');
}
for(i=1;i<=Q;i++){
scanf("%s",s+1);
x=(s[1]-'0')*50+(s[2]-'0');
y=(s[3]-'0')*50+(s[4]-'0');
z=(s[5]-'0')*50+(s[6]-'0');
G[z].push_back((node){x,y,i});
}
for(node u:G[0])ans[u.i]=f[u.x][u.y];
for(I=1;I<=m;I++){
cnt=0;
for(i=1;i<=n;i++)h[i]=rd[i]=vis[i]=0;
for(i=1;i<=n;i++)Ad(i,t[I][i]);
int Is=1,id0=0,id2=0;
for(i=1;i<=n;i++){
if(!vis[i]){
flg=0,I0=0,I2=0;DFS(i);
if(flg){Is=0;break;}
else{
if(I0&&I2){
if(!id0&&!id2)id0=I0,id2=I2;
else{Is=0;break;}
}
}
}
}
if(Is){
if(!id0&&!id2){for(i=1;i<=n;i++)Add(i,t[I][i]);}
else{
int p=0,q=0;
for(i=1;i<=n;i++){
if(t[I][i]==id2){if(!p)p=i;else q=i;}
}
Add(p,id0),Add(q,id0);
}
}
for(node u:G[I])ans[u.i]=f[u.x][u.y];
}
for(i=1;i<=Q;i++)printf("%d",ans[i]);putchar('\n');
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 8016kb
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: 6056kb
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: 84ms
memory: 7168kb
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: -100
Wrong Answer
time: 83ms
memory: 21968kb
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:
010101001101110010011000001010110111010001100011001100001000010101100101001000111110001100010010001101000101110000010110100100111101100000001000110100011001010001001001101000101010100100111101110110010000010000111100010011111010000010000101010010100010010101100101010111100010101000010101111101011111...
result:
wrong answer 1st lines differ - expected: '000101000101100010001000000010...0101000101000000000010101001000', found: '010101001101110010011000001010...0101000101000000000110101111100'