QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571511#9319. Bull FarmExusiai1WA 88ms7892kbC++202.3kb2024-09-17 23:51:162024-09-17 23:51:17

Judging History

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

  • [2024-09-17 23:51:17]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:7892kb
  • [2024-09-17 23:51:16]
  • 提交

answer

#include <bits/stdc++.h>
#define ll int
#define LL long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 2005
#define pb push_back
#define ld long double
#define all(x) x.begin(),x.end()
#define inf 1e18

using namespace std;
ll n,m,q;


ll a[N][N];


ll ask(ll x,ll y)
{
	return (x-48)*50+(y-48);
}


struct node{
	ll a,b,c,id;
	bool operator <(const node &A)const{
		return c<A.c;
	}
}t[Ma];
ll ans[Ma];


ll ru[N];
ll vis[N];
bitset <N> f[N];

void dfs(ll id,ll x)
{
	bitset <N> res=f[x];
	vis[x]=1;
	vector <ll> v;
	v.pb(x);
	while (!vis[a[id][x]])
		x=a[id][x],vis[x]=1,res|=f[x],v.pb(x);
	for (auto z:v)
		f[z]=res;
	return;
}

void go(ll x)
{
	for (ll i=1;i<=n;i++)
		ru[i]=0;
	ll cnt=0;
	for (ll i=1;i<=n;i++)
	{
		ru[a[x][i]]++;
		if (ru[a[x][i]]==2)
			cnt++;
		if (ru[a[x][i]]>2)
			return;
	}
	if (cnt>=2)
		return;
	ll z=0;
	for (ll i=1;i<=n;i++)
		if (!ru[i])
			z=i; 
	if (cnt)
	{
		for (ll i=1;i<=n;i++)
		{
			if (ru[a[x][i]]==2){
				for(int j=1;j<=n;j++){
					if(f[j][i])f[j]|=f[z];
				}
				// f[i]|=f[z];
			}
		}
		return;
	}
	for (ll i=1;i<=n;i++)
		vis[i]=0;
	for (ll i=1;i<=n;i++)
		if (!vis[i])
			dfs(x,i);
	return;
}


void sol()
{
	cin>>n>>m>>q;
	for (ll i=1;i<=n;i++)
		for (ll j=0;j<N;j++)
			f[i][j]=(i==j);
		
	for (ll i=1;i<=m;i++)
	{
		string s;
		cin>>s;
		for (ll j=1;j<=n;j++)
			a[i][j]=ask(s[j*2-2],s[j*2-1]);
	}
	/*printf("A=\n");
	for (ll i=1;i<=m;i++)
	{
		for (ll j=1;j<=n;j++)
			printf("%d ",a[i][j]);
		printf("\n");
	}*/

	for (ll i=1;i<=q;i++)
	{
		string s;
		cin>>s;
		ll x=ask(s[0],s[1]),y=ask(s[2],s[3]),z=ask(s[4],s[5]);
		t[i]={x,y,z,i};
		
	}	
	/*printf("T=\n");
	for (ll i=1;i<=q;i++)
		printf("%d %d %d %d\n",t[i].a,t[i].b,t[i].c,t[i].id);*/
	sort(t+1,t+q+1);
	ll x=0;
	for (ll i=1;i<=q;i++)
	{
		while (x<t[i].c) go(++x);
		if (f[t[i].a][t[i].b]) ans[t[i].id]=1;
		else ans[t[i].id]=0;
	}
	for (ll i=1;i<=q;i++)
		printf("%d",ans[i]);
	printf("\n");
	return;
}

int main()
{
	IOS
	ll tt=1;
	cin>>tt;
	while (tt--)
		sol();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 88ms
memory: 7892kb

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:

011110001101101111111111111111110101111111110111011110110110111011010101111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...

result:

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