Skip to content

Commit

Permalink
Merge pull request opencodeiiita#108 from Goddbott/main
Browse files Browse the repository at this point in the history
Create Problem
  • Loading branch information
rishabhking authored Dec 23, 2024
2 parents 548c925 + 2314bbe commit 6f46337
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Problem-setting/Goddbott-1/explanation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Explanation:

https://drive.google.com/file/d/11H9PEmoWNaFNNrrQ6WS2Oof5cvMt1CeR/view?usp=sharing

First we calculate the difference between the coordinates of starting point and ending point.
a= X2-X1 and b=Y2-Y1

One can observe that if a is greater than b or any of a or b is negative then it is impossible to reach the ending point.
If a is equal to b then one can directly move diagonally to reach the ending point in minimum time.
If a is less than b then we first move diagonally then move up to reach the ending point in minimum time.
25 changes: 25 additions & 0 deletions Problem-setting/Goddbott-1/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
int t;
cin>>t;
while(t--){
int m,n;
cin>>m>>n;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int a= x2-x1;
int b= y2-y1;
if (a<0 || b<0 || a>b){
cout<<-1<<endl;
continue;
}
else if (a==b){
cout<<a<<endl;
}
else if (b>a){
cout<<a+(y2-(y1+a))<<endl;
}
}
}
17 changes: 17 additions & 0 deletions Problem-setting/Goddbott-1/statement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
You are given a grid of width m and length n. The grid is made up of m*n boxes of dimensions 1*1. You are given a starting point (x1,y1) and an ending point (x2,y2).
You are only allowed to move 1 unit diagonally and 1 unit up. Every move by one unit takes 1 second. Find the minimum time it would take to reach the destination. If it is not possible then output -1.The problem contains T test cases.

Input Format:
The first line contains an integer T denoting the number of test cases.
In each test case
The first line contains integers m,n denoting the width and length of the grid.
The second line contains integers x1,y1 and x2,y2 denoting the starting and ending points.

Output:
Print the minimum time taken to reach the destination in a single line. If not possible then print -1.3

Constraints:
1<= T <= 10^5
1<= m,n <= 10^9
1<= x1,x2 <= m
1<= y1,y2 <= n
6 changes: 6 additions & 0 deletions Problem-setting/Goddbott-1/test0.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Input:
2
8 9
1 2 5 6
8 9
1 2 8 6
2 changes: 2 additions & 0 deletions Problem-setting/Goddbott-1/test0.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
4
-1

0 comments on commit 6f46337

Please sign in to comment.