QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21732#2832. Graph Theoryhy_zheng_zai_nei_juan#WA 9ms5704kbC++201.9kb2022-03-08 14:42:042022-05-08 04:00:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 04:00:15]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:5704kb
  • [2022-03-08 14:42:04]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
#define int ll
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO
{
    #define BUF_SIZE 100000
    bool IOerror=0;
    inline char nc()
	{
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if (p1==pend){
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if (pend==p1){IOerror=1;return -1;}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline ll read()
	{
        bool sign=0; char ch=nc();ll x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return 0;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
        return x;
    }
    #undef BUF_SIZE
};
using namespace fastIO;
int n,m,x[1000010],y[1000010];
bool check(int l)
{
	int mn=1,mx=2*n;;
	for(int i=1;i<=m;i++)
	{
		int lp,rp;
		if(y[i]-x[i]<=l)
		{
			if(x[i]+n-y[i]<=l)lp=1,rp=2*n;
			else lp=y[i],rp=x[i]+n;
		}
		else if(x[i]+n-y[i]<=l)lp=x[i],rp=y[i];
		else return 0;
		mn=max(mn,lp),mx=min(mx,rp);
	}
	return mn<mx;
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	while(n=qr,m=qr)
	{
		for(int i=1;i<=m;i++)
		{
			in(x[i]),in(y[i]);
			if(x[i]>y[i])swap(x[i],y[i]);
		}
		int l=0,r=n,ans;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(check(mid))ans=mid,r=mid-1;
			else l=mid+1;
		}
		cout<<ans<<'\n';
		n=0,m=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5704kb

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: 3ms
memory: 5596kb

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

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

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
14
4
1
3
11
6
2
9
3
14
10
17
10
14
4
12
12
7
11
12
7
8
9
13
2
3
2
11
7
9
5
6
3
17
4
1
14
9
17
2
6
5
1
2
2
3
6
13
13
10
4
10
7
9
5
12
1
8
4
3
1
5
8
7
7
5
6
9
12
11
3
3
9
7
8
5
6
9
8
1
4
2
7
1
16
7
3
9
4
6
7
5
7
9
1
9
14
5
8
5
5
4
8
10
11
6
9
2
11
5
3
10
10
10
1
2
2
6
6
13
11
7
3
5
1
3
7
2
1
17
13...

result:

wrong answer 3rd lines differ - expected: '8', found: '14'