QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#81822 | #2832. Graph Theory | AHSFNU_team_0# | WA | 8ms | 5668kb | C++14 | 1.3kb | 2023-02-26 14:06:32 | 2023-02-26 14:07:21 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MxM=200002;
int n,m,l,r,mid;
bool ok;
int a[MxM],b[MxM],cnt[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);
for(int i=1;i<=n;++i)cnt[i]=0;
int t=0;
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;
++t;
if(a[i]-b[i]>mid)
{
//printf(" %d ~ %d\n",b[i],a[i]-1);
++cnt[b[i]];
--cnt[a[i]];
}
if(b[i]-a[i]+n>mid)
{
//printf(" 1 ~ %d and %d ~ n\n",b[i]-1,a[i]);
++cnt[1];
--cnt[b[i]];
++cnt[a[i]];
}
}
for(int i=1;i<=n;++i)cnt[i]+=cnt[i-1];
//for(int i=1;i<=n;++i)printf("%d%c",cnt[i],i==n? '\n':' ');
for(int i=1;i<=n;++i)if(cnt[i]==t)return 1;
return 0;
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5668kb
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: 3656kb
input:
2 1 1 2
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 8ms
memory: 3816kb
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 8 0 0 0 7 7 9 0 4 8 0 8 2 0 2 0 0 0 5 0 0 0 0 1 0 0 9 0 0 4 0 0 0 3 6 8 0 0 0 0 0 6 0 8 0 0 0 0 0 5 8 0 0 5 0 7 0 0 3 0 0 7 0 5 0 6 5 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 7 10 7 0 0 0 0 6 0 0 7 0 0 0 0 7 2 0 0 9 0 0 0 0 0 1 0 0 3 0 0 0 8 0 0 3 0...
result:
wrong answer 2nd lines differ - expected: '6', found: '0'