QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554748 | #9251. Graph Changing | hewanying | Judgement Failed | / | / | C++14 | 1.0kb | 2024-09-09 15:21:01 | 2024-09-09 15:21:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int t,n,k,x,y;
void calc(){
if(y-x>=k) cout<<"1\n";
else if(x>k||n-y>=k) cout<<"2\n";
else if((x<=k&&n-x<k)||(y<=k&&n-y<k)) cout<<"-1\n";
else cout<<"3\n";
}
void SOLVE(){
cin>>t>>n>>k>>x>>y;
if(x>y) swap(x,y);
if(!t) cout<<y-x<<'\n';
else if(k>3){
if(t>=2) cout<<"-1\n";
else calc();
}else if(k==3){
if(n<=3) cout<<"-1\n";
else if(t==1) calc();
else if((t==2&&n==5&&x==2&&y==4)||(t==2&&n==7&&x==3&&y==5)||(t==3&&n==6&&x==2&&y==5)) cout<<"1\n";
else if(n==6&&t==2){
if(x==1||y==6) cout<<"-1\n";
else if(x==2&&y==5) cout<<"3\n";
else if(y<=3||x>3) cout<<"2\n";
else cout<<"1\n";
}else cout<<"-1\n";
}else if(k==2){
if(n<=2) cout<<"-1\n";
else if(n==3){
if(t==1&&x==1&&y==3) cout<<"1\n";
else cout<<"-1\n";
}else{
if(t&1) calc();
else cout<<y-x<<'\n';
}
}else cout<<"1\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int _;cin>>_;
while(_--) SOLVE();
return 0;
}
Details
Failed to show details