QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592790#9319. Bull Farmrevolutionary_oierWA 203ms11988kbC++144.1kb2024-09-27 07:36:042024-09-27 07:36:04

Judging History

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

  • [2024-09-27 07:36:04]
  • 评测
  • 测评结果:WA
  • 用时:203ms
  • 内存:11988kb
  • [2024-09-27 07:36:04]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn=2e3+10;
const int maxm=2e6+10;
int t,n,L,q,cnt_,l,tt;
char x[maxn<<2];
int fa[maxn],cnt[2],ct[maxn],dfn[maxn],low[maxn],h[maxn],deg[maxn];
bool in[maxn];
int c[maxn][maxn],head[2][maxn];
bitset<maxn>a[maxn],b[maxn];
struct qu{
	int S,T,num,ans,op;
}o[maxm];
struct node{
	int u,v,nxt;
}e[2][maxm],g[maxm];
inline int decode(char x,char y){
	int p=0;
	p=(x-'0')*50+y-'0';
	return p;
}
inline bool cmp(qu nx,qu ny){return nx.num<ny.num;}
inline bool cmp1(qu nx,qu ny){return nx.op<ny.op;}
inline void ipt(){
	tt=0;
	scanf("%lld%lld%lld",&n,&L,&q);
	for(int i=1;i<=n;i++)b[i]=0,fa[i]=i,b[i][i]=1;
	for(int i=1;i<=L;i++){
		scanf("%s",x);
		for(int j=0;j<2*n;j+=2)c[i][j/2+1]=decode(x[j],x[j+1]);
	}
//	for(int i=1;i<=L;i++){
//		for(int j=1;j<=n;j++)printf("%lld ",c[i][j]);
//		printf("\n");
//	}
	for(int i=1;i<=q;i++){
		scanf("%s",x);
		o[i].S=decode(x[0],x[1]);
		o[i].T=decode(x[2],x[3]);
		o[i].num=decode(x[4],x[5]);
		o[i].op=i;
		if(o[i].num==0){
			if(o[i].S==o[i].T)o[i].ans=1;
		}
	}
	sort(o+1,o+q+1,cmp);
}
inline void add0(int u,int v){
	e[0][++cnt[0]].v=v;
	e[0][cnt[0]].u=u;
	e[0][cnt[0]].nxt=head[0][u];
	head[0][u]=cnt[0];
}
inline bool make_graph(int k){
	cnt[0]=0;
	for(int i=1;i<=n;i++)head[0][i]=0;
	for(int i=1;i<=cnt[1];i++){
		int u=fa[e[1][i].u],v=fa[e[1][i].v];
		if(u==v)continue;
		add0(u,v);
	}
	for(int i=1;i<=n;i++)ct[i]=0;
	for(int i=1;i<=n;i++)ct[c[k][i]]++;
	int r=0;
	for(int i=1;i<=n;i++){
		if(ct[i]>2)return false;
		if(ct[i]==2)++r;
	}
	if(r>1)return false;
	if(r==0){
		for(int i=1;i<=n;i++)add0(fa[i],fa[c[k][i]]);
//		printf("k1 = %lld\n",k);
	}
	else {
//		printf("k2 = %lld\n",k);
		int s,s1=-1,s2=-1;
		for(int i=1;i<=n;i++){
			if(ct[i]==0)s=i;
			else if(ct[i]==2)r=i; 
		}
		for(int i=1;i<=n;i++){
			if(c[k][i]==r){
				if(s1==-1)s1=i;
				else s2=i;
			}
		}
		add0(fa[s1],fa[s]);
		add0(fa[s2],fa[s]);
	}
	return true;
}
stack<int>st;
inline void tarjan(int u){
	dfn[u]=low[u]=++tt;																																																																																																																																																				
	st.push(u);
	in[u]=true;
	for(int i=head[0][u];i;i=e[0][i].nxt){
		int v=e[0][i].v;
		if(!dfn[v]){
			tarjan(v);
			low[u]=min(low[v],low[u]);
		}
		else if(in[v])low[u]=min(low[v],low[u]);
	}
	if(low[u]==dfn[u]){
		int tmp;
		while(!st.empty()){
			tmp=st.top();
			st.pop();
			in[tmp]=false;
			fa[tmp]=u;
			if(u==tmp)break;
			b[u]|=b[tmp];
		}
	}
}
inline void add1(int u,int v){
	e[1][++cnt[1]].v=v;
	e[1][cnt[1]].u=u;
	e[1][cnt[1]].nxt=head[1][u];
	head[1][u]=cnt[1];
}
inline void add(int u,int v){
	g[++cnt_].v=v;
	g[cnt_].u=u;
	g[cnt_].nxt=h[u];
	h[u]=cnt_;	
}
inline void repair_graph(){
	cnt[1]=cnt_=0;
	for(int i=1;i<=n;i++)h[i]=head[1][i]=0;
	for(int i=1;i<=cnt[0];i++){
		int u=fa[e[0][i].u],v=fa[e[0][i].v];
//		printf("just_revolutionary_oier\n");
		if(u==v)continue;
//		printf("just_revolutionary_oier\n");
		add1(u,v);
		add(v,u);
		deg[u]++;
	}
}
queue<int>yt;
inline void topo_sort(){
	for(int i=1;i<=n;i++)a[i]=0;
	for(int i=1;i<=n;i++){
		a[i]=b[i];
		if(deg[i]==0)yt.push(i);
	}
	while(!yt.empty()){
		int u=yt.front();
		yt.pop();
		for(int i=h[u];i;i=g[i].nxt){
			int v=g[i].v;
			a[v]|=a[u];
			--deg[v];
			if(deg[v]==0)yt.push(v);
		}
	}
}
inline void query(int k){
	while(l<q+1){
		if(o[l].num==k){
			if(a[fa[o[l].S]][fa[o[l].T]])o[l].ans=1;
			else o[l].ans=0;
		}
		else if(o[l].num>k)break;
		++l;
	}
}
inline void solve(){
	l=1;
	for(int i=1;i<=L;i++){
		if(!make_graph(i)){
			query(i);
			continue;
		}
//		printf("I reached in Cheng Da community\n");
		tt=0;
		for(int j=1;j<=n;j++)dfn[j]=low[j]=0;
		for(int j=1;j<=n;j++){
			int u=fa[j];
			if(!dfn[u])tarjan(u);
		}
		repair_graph();
		topo_sort(); 
		query(i);
	}
	sort(o+1,o+q+1,cmp1);
	for(int i=1;i<=q;i++)printf("%lld",o[i].ans);
	printf("\n");
}
signed main(){
	scanf("%lld",&t);
	while(t--){
		ipt();
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9952kb

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: 0ms
memory: 11988kb

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: 203ms
memory: 11936kb

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:

011110000101101111111111111111100101001111110111011110010110001011010101111111111111111101111111111110001111110111010011111001101110111110111011111110110001110001100111111111111011111111111011101111010111100111111111011111111100111101001011010100111110111111110111111100111011001110011111011101111110...

result:

wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110000101101111111111111111...0111110111111101101111110111111'