QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#368214 | #2832. Graph Theory | hshshs# | WA | 0ms | 3668kb | C++14 | 827b | 2024-03-26 22:04:33 | 2024-03-26 22:04:33 |
Judging History
answer
#include<bits/stdc++.h>
#define maxn 200010
using namespace std;
int n,m,a[maxn],b[maxn],f[maxn];
int solve(int z){
memset(f,0,sizeof(f));
for(int i=1;i<=m;i++){
if(b[i]-a[i]>z&&n-(b[i]-a[i])>z)return 0;
else if(b[i]-a[i]<=z&&n-(b[i]-a[i])>z){
f[a[i]]++,f[b[i]]--;
}
else if(b[i]-a[i]>z&&n-(b[i]-a[i])<=z){
f[1]++,f[a[i]]--;
f[b[i]]++,f[n+1]--;
}
}
for(int i=1;i<=n;i++){
f[i]+=f[i-1];
if(f[i]==0)return 1;
}
return 0;
}
int main() {
freopen("F.in", "r", stdin);
while(~scanf("%d%d",&n,&m)){
for(int i=1;i<=m;i++)scanf("%d%d",&a[i],&b[i]);
for(int i=1;i<=m;i++)if(a[i]>b[i])swap(a[i],b[i]);
int l=0,r=n,mid,ans;
while(l<=r){
int mid=(l+r)>>1;
if(solve(mid))ans=mid,r=mid-1;
else l=mid+1;
}
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3668kb
input:
3 2 1 2 2 3 3 2 1 1 2 2 3 3 1 2 2 3 3 1
output:
result:
wrong answer 1st lines differ - expected: '1', found: ''