QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#62168#2832. Graph Theorywave#WA 9ms7700kbC++141.4kb2022-11-17 16:29:462022-11-17 16:29:55

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:29:55]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:7700kb
  • [2022-11-17 16:29:46]
  • 提交

answer

#include<queue>
#include<cmath>
#include<vector>
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define lp p<<1
#define rp (p<<1)+1
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=4e5+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);
	if(t[1].x!=1)return 1;
	int lr=t[1].y;
	for(int i=1;i<=num;i++)
	if(t[i].x<=lr)lr=max(lr,t[i].y);
	else{
		if(lr!=n+1)return 1;
	}
	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)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7588kb

input:

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

output:

1
0
2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5600kb

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 9ms
memory: 7700kb

input:

17 17
6 10
1 9
14 6
12 13
5 4
15 17
14 15
6 5
10 6
10 11
2 9
9 6
17 15
9 15
4 8
1 4
13 15
13 19
11 10
12 10
10 5
2 8
12 11
8 3
1 7
10 9
8 5
1 5
9 4
8 7
12 10
6 8
13 1
5 8
11 5
10 8
7 7
16 14
9 5
8 1
4 16
10 8
16 15
15 1
13 5
9 3
4 4
9 7
7 2
5 4
5 11
9 14
5 13
1 5
4 5
4 1
4 4
1 1
5 3
3 5
4 1
3 2
5 1
...

output:

8
6
8
2
1
2
7
6
2
6
2
9
10
10
8
10
3
8
7
7
9
10
4
8
6
8
2
2
2
6
6
5
5
4
2
9
4
1
9
6
9
2
6
4
1
2
1
3
6
8
8
6
3
4
7
6
3
8
1
5
3
2
1
5
8
5
7
5
6
7
10
9
3
2
6
7
4
5
6
6
5
1
4
2
4
1
9
7
3
9
4
6
7
5
7
6
1
5
8
5
6
4
5
3
3
7
7
6
9
2
7
3
3
7
10
7
1
2
2
6
6
7
8
7
2
5
1
3
7
2
1
9
9
5
9
5
2
3
1
6
6
3
8
6
1
8
3
...

result:

wrong answer 411th lines differ - expected: '2', found: '5'