QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21721 | #2832. Graph Theory | s8194272# | WA | 15ms | 3640kb | C++14 | 1.9kb | 2022-03-08 14:31:50 | 2022-05-08 03:59:26 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#define fi first
#define se second
#define max Max
#define min Min
#define abs Abs
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define fan(x) (((x-1)^1)+1)
#define mp(x,y) make_pair(x,y)
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
#define INF 0x3f3f3f3f
using namespace std;
inline int read()
{
int ans=0,f=1;
char c=getchar();
while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
return ans*f;
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x/10) write(x/10);
putchar((char)(x%10)+'0');
}
template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a<b?a:b;}
template<typename T,typename TT> inline T Max(T a,TT b){return a<b?b:a;}
const int N=2e5+5;
int n,m,b[N];
struct Node
{
int x,y;
}a[N];
inline void add(int l,int r)
{
if(l>r) return;
b[l]++;b[r+1]--;
}
inline bool check(int x)
{
for(int i=1;i<=m;++i)
{
int p1=a[i].y-a[i].x;
int p2=a[i].x+n-a[i].y;
if(p1<=x&&p2<=x) continue;
if(p1>x&&p2>x) return 0;
if(p1>x) add(1,a[i].x-1),add(a[i].y,n);
if(p2>x) add(a[i].x,a[i].y-1);
}
int flag=0;
for(int i=1;i<=n;++i)
{
b[i]+=b[i-1];
if(b[i]==0) flag=1;
}
for(int i=1;i<=n+1;++i)
b[i]=0;
return flag;
}
signed main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=1;i<=m;++i)
{
a[i].x=read();
a[i].y=read();
if(a[i].x>a[i].y)
swap(a[i].x,a[i].y);
}
int l=0,r=n+2,ps=n+1;
while(l<=r)
{
if(check(mid))
ps=mid,r=mid-1;
else l=mid+1;
}
write(ps);puts("");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
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: 3640kb
input:
2 1 1 2
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 15ms
memory: 3628kb
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 155th lines differ - expected: '4', found: '6'