QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586968#9319. Bull FarmAlliy666WA 25ms5764kbC++232.1kb2024-09-24 16:50:202024-09-24 16:50:20

Judging History

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

  • [2024-09-24 16:50:20]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:5764kb
  • [2024-09-24 16:50:20]
  • 提交

answer

#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn=2005;
int tt[maxn],s[maxn];
bitset<maxn> flag;
class A
{
public:
	int to,val;
};
vector<A> G[maxn];
class B
{
public:
	int num,dis;
	bool operator<(const B&that)const
	{
		return dis>that.dis;
	}
};
int dis[maxn][maxn];
int input()
{
	int ans=0;
	int a='\n',b='\n';
	while(a=='\n')
		a=getchar();
	while(b=='\n')
		b=getchar();
	return 50*(a-48)+b-48;
}
int find(int d)
{
	if(s[d]!=d)
		s[d]=find(s[d]);
	return s[d];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t,n,l,q,u,v,a,b,c;
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d %d %d\n",&n,&l,&q);
		for(int i=1;i<=n;i++)
		{
			s[i]=i;
			G[i].clear();
		}
		for(int i=1;i<=l;i++)
		{
			flag.reset();
			for(int j=1;j<=n;j++)
			{
				tt[j]=input();
				flag[tt[j]]=1;
			}
			int cnt=flag.count();
			if(cnt==n)
			{
				for(int j=1;j<=n;j++)
				{
					u=find(j);
					v=find(tt[j]);
					if(u!=v)
					{
						s[u]=v;
						G[u].push_back({v,i});
						G[v].push_back({u,i});
					}
				}
			}
			else if(cnt==n-1)
			{
				gp_hash_table<int,int> mp;
				flag.flip();
				v=flag._Find_next(0);
				for(int j=1;j<=n;j++)
				{
					if(mp.find(tt[j])==mp.end())
						mp[tt[j]]=j;
					else
					{
						G[mp[tt[j]]].push_back({v,i});
						G[j].push_back({v,i});
						break;
					}
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			std::priority_queue<B> q;
			q.push({i,0});
			for(int j=1;j<=n;j++)
			{
				if(j!=i)
					dis[i][j]=2147483647;
				else
					dis[i][j]=0;
			}
			while(!q.empty())
			{
				B now=q.top();
				q.pop();
				if(dis[i][now.num]!=now.dis)
					continue;
				for(auto j:G[now.num])
				{
					if(dis[i][j.to]>j.val)
					{
						dis[i][j.to]=j.val;
						q.push({j.to,j.val});
					}
				}
			}
		}
		while (q--)
		{
			a=input();
			b=input();
			c=input();
			if(dis[a][b]<=c)
				putchar('1');
			else
				putchar('0');
		}
		putchar('\n');
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 25ms
memory: 4044kb

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:

011110101101111111111111111111111111111111110111111111111111111011010111111111111111111101111111111110111111110111111111111111111111111111111111111111111111110001110111111111111111111111111011101111111111111111111111111111111111111111111011110100111111111111111111111100111111101110111111111101111110...

result:

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