QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578307#9319. Bull FarmYoralenWA 2ms6156kbC++142.2kb2024-09-20 18:08:012024-09-20 18:08:01

Judging History

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

  • [2024-09-20 18:08:01]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6156kb
  • [2024-09-20 18:08:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2005;
bitset<N>f[N];
int Te,rd[N],ans[N];
struct node{int x,y,i;};
vector<node>G[N];
struct Edge{int to,next;}w[N<<1];
int cnt=0,h[N],vis[N],flg,I0,I2,n,m,Q,t[N][N];
char s[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]==1){;}
	else if(rd[u]==2){if(!I2)I2=u;else flg=1;}
	else 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;
	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(int 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'); 
	    //	printf("%d %d %d\n",x,y,z);
	    	G[z].push_back((node){x,y,i});
	    }
	    //putchar('\n');
	    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,tp=0,id0=0,id2=0;
		//	printf("%d:\n",I);
		//	for(i=1;i<=n;i++)printf("%d ",rd[i]);putchar('\n');
	    	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){
	    	//	printf("~%d %d %d\n",I,id0,id2);
	    		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: 0ms
memory: 4024kb

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

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

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:

011010001000101011000000001101111001011101110111011110000000011011000111110001000001001000110011110000001101100011100101000101101000010110110101010110001111000000000011101011110111010001111001100000011011010011101110111001001010110010001011110000010010001001100110101000100110001110100000111100101000...

result:

wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011010001000101011000000001101...0101101010010101001101011101101'