QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#566843#9319. Bull FarmYzm007RE 40ms6204kbC++144.5kb2024-09-16 02:19:462024-09-16 02:19:48

Judging History

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

  • [2024-09-16 02:19:48]
  • 评测
  • 测评结果:RE
  • 用时:40ms
  • 内存:6204kb
  • [2024-09-16 02:19:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
#define fi first
#define se second
#define pb push_back
#define dbg(x) cerr<<(#x)<<":"<<x<<" ";
#define dbg2(x) cerr<<(#x)<<":"<<x<<endl;
#define SZ(a) (int)(a.size())
#define sci(a) scanf("%d",&(a))
#define scll(a) scanf("%lld",&(a))
#define pt(a) printf("%d",a);
#define pte(a) printf("%d\n",a)
#define ptlle(a) printf("%lld\n",a)
#define debug(...) fprintf(stderr, __VA_ARGS__)
const int N=2e3+10,M=5e3+10,X=1e6+10,maxn=N,maxm=10*N;
int c,n,l,q,g[105][105];
int to[N][N],par[N],deg[N],Q[N],now[N];
char s[M],ans[X];
vector<array<int,3>>ask[N];
int head[maxn],cnt;
int low[maxn],dfn[maxn],num;//最早非负祖先时间戳 时间戳 
int stk[maxn],top;//用数组模拟栈 栈顶 当前栈顶值 
int col[maxn],tot;//染色 颜色数 
bool in[maxn];//是否在栈中 
vector<int>all,F[N];
P E[maxm];
int find(int x){
	return par[x]==x?x:par[x]=find(par[x]);
}
void mer(int x,int y){
	//if(!x || !y)while(1);
	x=find(x),y=find(y);
	if(x==y)return;
	par[y]=x;
}
int f(char x,char y){
	int nx=x,ny=y;
	//if(nx>100 || ny>100)while(1);
	return g[nx][ny];
}
struct edge{
	int to,next;
}e[maxm];
void add(int u,int v){
	e[++cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
void dfs(int u){
	low[u]=dfn[u]=++num;
	in[u]=1;
	stk[++top]=u;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(!dfn[v]){
			dfs(v);
			low[u]=min(low[u],low[v]);
		}
		else if(in[v]){
			low[u]=min(low[u],dfn[v]);
		}
	}
	if(low[u]==dfn[u]){
		tot++;
		int now;
		do{
			now=stk[top--];
			col[now]=tot;
			in[now]=0; 
		}while(now!=u);
	}
}
void init(int n){
	memset(head,0,(n+5)*sizeof(int));
	memset(in,0,(n+5)*sizeof(int));
	memset(dfn,0,(n+5)*sizeof(int));
	memset(low,0,(n+5)*sizeof(int));
	memset(deg,0,(n+5)*sizeof(int));
	memset(now,0,(n+5)*sizeof(int));
	cnt=num=top=tot=0;
	rep(i,1,n)F[i].clear();
}

template<int LEN>void solve(int p){
	if(LEN<=n){solve<min(N,LEN<<1)>(p);return;}
	if(p){
		init(n);
		bool no=0;
		int two=0;
		rep(j,1,n){
			int v=to[p][j];	
			now[v]++;
			if(now[v]==2)two++;
			if(now[v]==3)no=1;
		}
		if(two>=2)no=1;
		//printf("i:%d no:%1d two:%d\n",i,no,two);
		if(!no){
			if(!two){
				rep(j,1,n){
					int v=to[p][j];
					if(j==v)continue;
					//printf("p:%d j:%d v:%d\n",p,j,v);
					mer(j,v);
				}
			}
			else{
				int pos=0;
				rep(j,1,n){
					if(!now[j]){
						pos=j;
						break;
					}
				}
				rep(j,1,n){
					int v=to[p][j];
					if(now[v]==2){
						E[++c]=P(j,pos);
					}
				}	
			}
		}
		all.clear();
		rep(j,1,c){
			int u=E[j].fi,v=E[j].se;
			int fj=find(u),fp=find(v);
			//printf("p:%d j:%d v:%d pos:%d\n",p,j,v,pos);
			if(fj==fp)continue;
			add(fj,fp);
		}
		rep(j,1,n){
			if(find(j)==j){
				//printf("p:%d j:%d\n",p,j);
				all.pb(j);
				if(!dfn[j])dfs(j);
			}
		}
		vector<bitset<LEN>>can(n+1,0);
		int t=0;
		for(auto &u:all){
			for(int i=head[u];i;i=e[i].next){
	    		int v=e[i].to;
	    		//printf("u:%d v:%d\n",u,v);
	    		if(col[u]==col[v])continue;
				F[col[u]].pb(col[v]);
				deg[col[v]]++;
			}
		}
		rep(i,1,tot){
			if(!deg[i])Q[t++]=i;
		}
		for(int s=0;s<t;++s){
			int u=Q[s];
			for(auto &v:F[u]){
				if((--deg[v])==0){
					Q[t++]=v;
				}
			}
		}
		for(int i=t-1;i>=0;--i){
			int u=Q[i];
			if(u>LEN)while(1);
			can[u][u]=1;
			for(auto &v:F[u]){
				can[u]|=can[v];
			}
		}
		for(auto &x:ask[p]){
			int a=x[0],b=x[1],id=x[2];
			//printf("a:%d fa:%d b:%d fb:%d ca:%d cb:%d\n",a,find(a),b,find(b),col[find(a)],col[find(b)]);
			a=col[find(a)],b=col[find(b)];
			ans[id]=can[a].test(b)?'1':'0';
		}
	}
	else{
		for(auto &x:ask[p]){
			int a=x[0],b=x[1],id=x[2];
			ans[id]=(a==b)?'1':'0';
		}
	}
}
void sol(){
	sci(n),sci(l),sci(q);
	rep(i,1,n)par[i]=i;
	rep(i,1,l){
		scanf("%s",s+1);
		for(int j=1;j<=2*n;j+=2){
			to[i][(j+1)/2]=f(s[j],s[j+1]);
			//printf("%d ",to[i][(j+1)/2]);
		}
		//puts("");
	}
	c=0;
	rep(i,1,q){
		scanf("%s",s+1);
		int a=f(s[1],s[2]),b=f(s[3],s[4]),p=f(s[5],s[6]);
		//printf("%d %d %d\n",a,b,c);
		ask[p].pb({a,b,i});
	}
	rep(i,0,l){
		solve<1>(i);
	}
	rep(i,0,l)ask[i].clear();
	ans[q+1]='\0';
	printf("%s\n",ans+1);
}
int main(){
	rep(i,0,2000){
		int x=48+(i/50),y=48+(i%50);
		g[x][y]=i;
	}
	int T;
	sci(T); // t=1
	while(T--){
		sol();
	}
	return 0;
}

详细

Test #1:

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

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

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: 40ms
memory: 6152kb

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
Runtime Error

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:


result: