QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287663 | #2832. Graph Theory | geruome# | WA | 12ms | 5672kb | C++14 | 1.3kb | 2023-12-20 21:23:19 | 2023-12-20 21:23:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,l,r) for(int i=(l); i<=(r); i++)
#define per(i,r,l) for(int i=(r); i>=(l); i--)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
const int N=2e5+5;
int n,m;
P eg[N];
int d[N],X;
bool ck(int res){
rep(i,0,n)d[i]=0;
auto add=[&](int l,int r){
// cout<<l<<" "<<r<<endl;
++d[l]; --d[r];
};
rep(i,1,m){
auto [u,v]=eg[i];
if(u==v)continue;
int v1=(v-u)<=res,v2=(u+n-v)<=res;
// cout<<v1<<" "<<v2<<endl;
if(v1 && v2)continue;
else if(!v1 && !v2)return false;
if(v1){
add(u,v);
}
else if(v2){
add(u,n+1); add(1,v);
}
}
rep(i,1,n){
d[i]+=d[i-1]; assert(d[i]>=0);
if(!d[i]){X=i;return true;}
}
return false;
}
void slv(){
rep(i,1,m){
int u,v; cin>>u>>v;
if(u>v)swap(u,v);
eg[i]={u,v};
}
int L=0,R=n;
// cout<<ck(1)<<endl; return;
while(L<=R){
int mid=(L+R)>>1;
if(ck(mid))R=mid-1;
else L=mid+1;
}
cout<<L<<"\n";
}
signed main(){
IOS
while(cin>>n>>m){
slv();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5672kb
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: 0ms
memory: 3624kb
input:
2 1 1 2
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 12ms
memory: 3632kb
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 12 14 4 1 3 11 6 2 9 3 14 14 17 14 18 5 13 12 13 11 18 7 11 10 13 2 3 2 11 9 9 13 6 3 17 4 1 15 10 17 2 6 5 1 4 2 4 11 13 13 10 4 11 10 11 5 12 1 8 5 3 1 8 8 8 10 8 11 9 12 15 3 3 9 10 8 5 10 11 8 1 4 4 8 1 18 13 5 14 4 6 7 7 10 11 1 9 14 11 9 5 9 4 8 10 11 6 12 2 14 5 6 10 15 12 1 4 2 6 12 13 14 ...
result:
wrong answer 2nd lines differ - expected: '6', found: '12'