QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#62199#2832. Graph Theorywave#TL 0ms0kbC++1.3kb2022-11-17 16:59:152022-11-17 16:59:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-17 16:59:17]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-11-17 16:59:15]
  • 提交

answer

#include<queue>
#include<cmath>
#include<vector>
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

template<typename T>void read(T &x){
    x=0;int w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x=x*w;
}

typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=5e5+5;

int n,m,a[N],b[N];

struct pp{
	int x,y;
}t[N];
int cmp(pp aa,pp bb){return aa.x<bb.x;}

int pd(int mid){
	int num=0;
	for(int i=1;i<=m;i++){
		if(a[i]==b[i])continue;
		int d1=b[i]-a[i],d2=n-b[i]+a[i];
		if(d1>mid&&d2>mid)return 0;
		if(d1<=mid&&d2>mid)
		t[++num].x=a[i],t[num].y=b[i];
		if(d2<=mid&&d1>mid){
			t[++num].x=1;t[num].y=a[i];
			t[++num].x=b[i];t[num].y=n+1;
		}
	}
	sort(t+1,t+1+num,cmp);
	int lr=1;
	for(int i=1;i<=num;i++)
	if(t[i].x<=lr)lr=max(lr,t[i].y);
	
	if(lr==n+1) return 0;
	else return 1;
}
void solve(){
	int ff=0;
	for(int i=1;i<=m;i++){
		read(a[i]);read(b[i]);
		if(a[i]!=b[i])ff=1;
		if(a[i]>b[i])swap(a[i],b[i]);
	}
	if(!ff){
		printf("0\n");
		return;
	}
	int l=1,r=n*2,ans=n;
	while(l<=r){
		int mid=(l+r)/2;
		if(pd(mid)) r=mid+1;
		else l=mid+1;
	}
	printf("%d\n",ans);
}

int main(){
	while(scanf("%d%d",&n,&m)!=EOF)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

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

output:


result: