QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#81814 | #2832. Graph Theory | AHSFNU_team_0# | WA | 10ms | 3596kb | C++14 | 1.2kb | 2023-02-26 13:55:40 | 2023-02-26 13:55:43 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MxM=200002;
int n,m,l,r,mid,l1,r1,l2,r2;
bool ok;
int a[MxM],b[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);
l1=l2=1,r1=r2=n;
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;
if(a[i]-b[i]>mid)
{
//printf(" %d ~ %d\n",b[i],a[i]-1);
l1=max(l1,b[i]);
l2=max(l2,b[i]);
r1=min(r1,a[i]-1);
r2=min(r2,a[i]-1);
}
if(b[i]-a[i]+n>mid)
{
//printf(" 1 ~ %d and %d ~ n\n",b[i]-1,a[i]);
r1=min(r1,b[i]-1);
l2=max(l2,a[i]);
}
}
return l1<=r1 || l2<=r2;
}
int main()
{
for(;~scanf("%d%d",&n,&m);)
{
ok=0;
for(int i=1;i<=m;++i)
{
read(a[i]),read(b[i]),ok|=(a[i]==b[i]);
if(a[i]<b[i])swap(a[i],b[i]);
}
if(ok)
{
puts("0");
continue;
}
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: 100
Accepted
time: 2ms
memory: 3592kb
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: 2ms
memory: 3596kb
input:
2 1 1 2
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 10ms
memory: 3568kb
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 0 0 0 1 0 0 0 2 0 0 9 0 0 10 0 0 0 7 7 9 0 7 8 0 13 2 0 2 0 0 0 5 0 0 0 0 1 0 0 13 0 0 5 0 0 0 3 6 12 0 0 0 0 0 9 0 8 0 0 0 0 0 5 8 0 0 5 0 9 0 0 3 0 0 7 0 5 0 9 6 0 4 0 0 0 0 7 0 9 4 6 0 5 0 0 0 0 0 5 6 4 0 0 0 0 0 6 9 0 0 0 3 10 10 7 0 0 0 0 6 0 0 7 0 0 0 0 7 2 0 0 13 0 0 0 0 0 1 0 0 3 0 0 0 11 ...
result:
wrong answer 2nd lines differ - expected: '6', found: '0'