QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#63280 | #2832. Graph Theory | kasiruto# | RE | 2ms | 3476kb | C++17 | 1.0kb | 2022-11-21 14:15:57 | 2022-11-21 14:16:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
void work(){
vector<int>a(n+1),b(n+1);
for (int i=1;i<=m;i++){
cin>>a[i]>>b[i];
if (a[i]>b[i]) swap(a[i],b[i]);
}
auto pd=[&](int mid){
vector<int>p(n+3);
for (int i=1;i<=m;i++){
int x1=b[i]-a[i],x2=n-x1;
if (min(x1,x2)>mid) return false;
if (max(x1,x2)<=mid) continue;
if (x1<=mid) p[a[i]]++,p[b[i]]--;
else{
p[b[i]]++,p[n+1]--;
p[1]++,p[a[i]]--;
}
}
for (int i=1;i<=n;i++){
p[i]=p[i-1]+p[i];
if (p[i]==0) return true;
}
return false;
};
int l=0,r=n,mid;
while (l<r){
mid=(l+r)/2;
if (pd(mid)) r=mid;
else l=mid+1;
}
cout<<l<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef LC
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
#endif
while (cin>>n>>m)
work();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3476kb
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: 3372kb
input:
2 1 1 2
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Dangerous Syscalls
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 ...