This seems unreasonable:
- Status: Time Limit Exceeded
- Time: 0.00 sec
- Solution: 45414771
In the 24th line, Math.max(N - a, M - b) should be there.
Great! Thanks for keeping it simple!
I have tried the exact same approach (atleast I believe that), yet I’ve faced the Wrong Answer verdict.
Here’s the direct link to my Python 3 submission for the problem: CodeChef: Practical coding for everyone
Can anyone please provide me a testcase for which it is failing, or any other error if spotted will be highly appreciated. ![]()
Update: The issue has been resolved. It was the wrong order of inputs that trapped me. I thought x, a and y, b were given, instead of x, y and a, b. The line from constraints had reset me. ![]()
I will try to stay awake in the next one (i.e., April Lunchtime) ![]()
Why is using distance between two points(((x1-x2)^2)+(y1-y2)^2)^1/2) for police wrong?
I used this in the contest and got WA. I translated the points to the original x-axis,y-axis during this.
For thief, I calculated using((n-p) + (m-q))
This is because of the described movement in the question. The police cannot break the right, down and diagonal movement to choose the displacement upto (N, M). Your formula would give displacement, while we needed to account for the step by step distance (per unit time).
Police can only travel in angles of 0, -45, and -90 degrees.
Note also that the number of moves from (0,0) to (100,100) is 100, but the distance from the formula is 141.
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
// your code goes here
ll tc;
cin>>tc;
while(tc--){
ll n,m;
cin>>n>>m;
ll x,y;
cin>>x>>y;
ll a,b;
cin>>a>>b;
ll ts=abs(x-n)+abs(y-m);
ll ps=0;
ll tx,ty;
if(a!=n && b!=m){
ll tx=a+min(abs(n-a), abs(m-b));
ll ty=b+min(abs(n-a), abs(m-b));
ps=min(abs(n-a), abs(m-b));
ps+=(abs(n-tx)+abs(m-ty));
}
else {
ps+=(abs(n-a)+abs(m-b));
}
if(ps<=ts){
cout<<"NO"<<endl;
}
else {
cout<<"YES"<<endl;
}
}
return 0;
}
Could someone please tell me what is wrong with my code ? I have calculated steps for policeman as max steps he could go in diagonal way + straight steps for the rest of the journey. Someone kindly point out what is wrong with this.
test cases are quite high you should use fast input and output…
Thank you.
Evidently that is the case. In my Java implementation, I switched from using Scanner to BufferedReader, and it worked. It made it much longer, but this will be an important note for the future. 45431543
In simple terms, Since both the players are playing optimally, both of them will try to reach cell (N, M) whoever reaches the cell first, wins the game.
Now the problem boils down to finding the smallest distance from both the points to cell (N, M)
Can anybody help me with this?
Same logic
Got AC in C++ Solution
But getting TLE in JAVA??? Solution
I generally do code in java And i was thinking in mid of contest may be my approach is incorrect
and when i saw code of other peoples post contest my mind is blown up…
Use Fast IO
why it’s showing wrong answer even though passing mentioned testcases…
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n,m,x,y,a,b;
cin>>n>>m>>x>>y>>a>>b;
int tp=0,tc=0;
if(a==b){
tp+=(n-a);
}
else{
(a==n)?tp+=(m-b):tp+=(n-a);
}
tc+=(n-x)+(m-y);
if(tp<tc) cout<<"NO"<<"\n";
else
cout<<"YES"<<"\n";
}
}
Plzzz anybody give reason…!!1
This seems wrong.
What if a \neq n but m-b > n-a? You are doing tp+=(n-a) in this case which is wrong. You should do tp = max(n-a, m-b) instead.
Just curious, in your Java solution, you have written a function to swap Integers.
public static void swap(int a, int b){
int temp=a;
a=b;
b=temp;
}
Do you really think this function swaps Integers 
haha! yes you are right , definitely it is not gonna swap integers
i have just written to use it for another purpose
can anybody tell me what’s wrong with my code.
I had done exactly same but getting wrong answer error.
#include (iostream is not shown here because of #)
using namespace std;
int policedp(int n,int m,int a,int b)
{
int x = n-a;
int y = n-b;
if(x>y)
return x;
else
return y;
}
int thiefdp(int n,int m,int x,int y)
{
return (n-x+m-y);
}
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int x,y;
cin>>x>>y;
int a,b;
cin>>a>>b;
int police = policedp(n,m,a,b);
int thief = thiefdp(n,m,x,y);
if(police<thief)
cout<<"NO\n";
else
cout<<"YES\n";
}
return 0;
}
int x = m - a;
int y = n - b; //(may be)
t = int(input())
while t>0:
m , n = map(int , input().split())
x , y = map(int , input().split())
a , b = map(int , input().split())
Tt = n - x + m - y
Tp = max(n-a , m-b)
if Tp<Tt:
print("NO")
else:
print("YES")
t-=1
Can anyone tell me why am I getting WA? I am getting correct output with the given test case.