QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#81832#2832. Graph TheoryAHSFNU_team_0#WA 2ms3404kbC++141.2kb2023-02-26 14:27:572023-02-26 14:28:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-26 14:28:06]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3404kb
  • [2023-02-26 14:27:57]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MxM=200002;
int n,m,l,r,mid;
int a[MxM],b[MxM],cnt[MxM];
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0' || ch>'9')f|=(ch=='-'),ch=getchar();
	while(ch>='0' && ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x=f? -x:x;return ;
}
inline bool check()
{
	//printf(" check %d\n",mid);
	for(int i=1;i<=n;++i)cnt[i]=0;
	int t=0;
	for(int i=1;i<=m;++i)
	{
		if(a[i]-b[i]>mid && b[i]-a[i]+n>mid)return 0;
		if(a[i]-b[i]<=mid && b[i]-a[i]+n<=mid)continue;
		++t;
		if(a[i]-b[i]>mid)
		{
			//printf(" %d ~ %d\n",b[i],a[i]-1);
			++cnt[b[i]];
			--cnt[a[i]];
		}
		if(b[i]-a[i]+n>mid)
		{
			//printf(" 1 ~ %d and %d ~ n\n",b[i]-1,a[i]);
			++cnt[1];
			--cnt[b[i]];
			++cnt[a[i]];
		}
	}
	for(int i=1;i<=n;++i)cnt[i]+=cnt[i-1];
	//for(int i=1;i<=n;++i)printf("%d%c",cnt[i],i==n? '\n':' ');
	for(int i=1;i<=n;++i)if(cnt[i]==t)return 1;
	return 0;
}
int main()
{
	for(;~scanf("%d%d",&n,&m);)
	{
		for(int i=1;i<=m;++i)
		{
			read(a[i]),read(b[i]);
			if(a[i]<b[i])swap(a[i],b[i]);
		}
		for(l=1,r=n;l<=r;)
		{
			mid=((l+r)>>1);
			if(check())r=mid-1;
			else l=mid+1;
		}
		printf("%d\n",l);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3404kb

input:

3 2
1 2
2 3
3 2
1 1
2 2
3 3
1 2
2 3
3 1

output:

1
1
2

result:

wrong answer 2nd lines differ - expected: '0', found: '1'