QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572015#9319. Bull FarmzhouhuanyiWA 75ms4016kbC++231.6kb2024-09-18 11:06:552024-09-18 11:06:56

Judging History

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

  • [2024-09-18 11:06:56]
  • 评测
  • 测评结果:WA
  • 用时:75ms
  • 内存:4016kb
  • [2024-09-18 11:06:55]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#define N 2000
using namespace std;
const int inf=(int)(1e9);
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int get()
{
	char a=0,b;
	while (a<'0'||a>'a') a=getchar();
    b=getchar();
	return (a-48)*50+b-48;
}
int T,n,l,q,st,t[N+1],cnt[N+1],rt[N+1],dis[N+1][N+1];
vector<int>E[N+1];
int find(int x)
{
	if (rt[x]==x) return x;
	return rt[x]=find(rt[x]);
}
void unionn(int x,int y)
{
	rt[x]=y;
	return;
}
void solve(int x,int y)
{
	dis[x][y]=st;
	for (int i=0;i<E[y].size();++i)
		if (dis[x][E[y][i]]==inf)
			solve(x,E[y][i]);
	return;
}
void add(int x,int y)
{
	E[x].push_back(y);
	for (int i=1;i<=n;++i)
		if (dis[i][x]!=inf&&dis[i][y]==inf)
			solve(i,y);
	return;
}
int main()
{
	int a,b,c,srt,res;
	T=read();
	while (T--)
	{
		n=read(),l=read(),q=read();
		for (int i=1;i<=n;++i)
			for (int j=1;j<=n;++j)
				dis[i][j]=(i==j)?0:inf;
		for (int i=1;i<=n;++i) rt[i]=i;
		for (int i=1;i<=l;++i)
		{
			st=i;
			for (int j=1;j<=n;++j) cnt[j]=0;
			for (int j=1;j<=n;++j) t[j]=get(),cnt[t[j]]++;
			res=0;
			for (int j=1;j<=n;++j) res+=max(cnt[j]-1,0);
			if (!res)
			{
				for (int j=1;j<=n;++j)
					if (find(j)!=find(t[j]))
						add(j,t[j]),add(t[j],j);
			}
			else if (res==1)
			{
				srt=0;
				for (int j=1;j<=n;++j)
					if (!cnt[j])
						srt=j;
				for (int j=1;j<=n;++j)
					if (cnt[t[j]]==2)
						add(j,srt);
			}
		}
		while (q--) a=get(),b=get(),c=get(),printf("%d",c>=dis[a][b]);
		puts("");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 75ms
memory: 4016kb

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:

wrong answer 2nd lines differ - expected: '111111011101111011011111111111...1111110111111110111011110101111', found: '111111011111111011011111111111...1111110111111111111011110111111'