QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#593560 | #9251. Graph Changing | ucup-team2681 | WA | 0ms | 3684kb | C++23 | 1.4kb | 2024-09-27 14:37:52 | 2024-09-27 14:37:53 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
ll t,n,k,x,y;
ll calc(ll a,ll b){
if(abs(a-b)>=k)return 1;
if((a-1>k&&n-a>k)||(b-1>k&&n-b>k))return -1;
if((a-1>=k&&b-1>=k)||(n-a>=k&&n-b>=k))return 2;
return 3;
}
void solve(){
cin>>t>>n>>k>>x>>y;
if(x>y)swap(x,y);
if(t==0){
cout<<y-x<<"\n";
return;
}
if(k==1){
cout<<"1\n";
return;
}
if(k==2){
if(n==2){
cout<<"-1\n";
return;
}
if(n==3){
if(t==1&&x==1&&y==3)cout<<"1\n";
else cout<<"-1\n";
return;
}
if(t&1){
cout<<calc(x,y)<<"\n";
}
else{
cout<<y-x<<"\n";
}
return;
}
if(t>=2){
if(k==3&&t==2){
if(n==5&&x==2&&y==4){
cout<<"1\n";
return;
}
if(n==6){
if(x==1||y==6){
cout<<"-1\n";
return;
}
if((x==2&&y==3)||(x==4&&y==5))cout<<"2\n";
else cout<<"1\n";
return;
}
if(n==7){
if(x==3&&y==5){
cout<<"1\n";
return;
}
}
}
cout<<"-1\n";
return;
}
else{
if((x-1<k&&n-x<k)||(y-1<k&&n-y<k)){
cout<<"-1\n";
}
else{
if(y-x>=k)cout<<"1\n";
else{
if((x-1>=k&&y-1>=k)||(n-x>=k&&n-y>=k))cout<<"2\n";
else cout<<"3\n";
}
}
return;
}
assert(0);
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t=1;
cin>>t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 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