alternatively, make an another array containing indices, sort them using the first array. then assign some common number to those frogs who can communicate. ( In sample test case, indices becomes 0 1 3 2 4 and we have to check if v[1]-v[0]<=k) if yes then assign some common value to them ).
I solved the problem in two ways: Using Segment Trees, Using concept of connected component as pointed out by @brobear1995
But I haven’t thought of a DP solution…I always miss out on DP…
Same thing I do but still getting TLE
I sorted them using quick sort and then
go through min coordinate to max coordinate and note down every starting point after breaking point say if coordinates are 0 8 5 3 12 and distance is 3 than i stored 0 12 in new array
than i take input from user and get coordinate of there position and look for whether they belong to same interval or not if yes than answer is yes else no. Link to solution
Please tell me what wrong in my code
Sir, i have used this code and getting correct answer for all the test cases which i have tried…i am still getting WA…please help where is the error in the code?? http://www.codechef.com/viewsolution/4254933
Sir, I have used my code for most of the test cases and getting the desired output…still I am getting WA…Kindly tell the respective cases for which my code was wrong…Thank you http://www.codechef.com/viewsolution/4297541
int frogs=sc.nextInt();
int distance=sc.nextInt();
int pairs=sc.nextInt();
int[] a=new int[frogs];
for(int i=0;i<frogs;i++){a[i]=sc.nextInt();}
while(pairs-->0){
int n1=sc.nextInt(); int n2=sc.nextInt();
int p1=a[n1-1]; int p2=a[n2-1]; int m=0;
Arrays.sort(a);
for(int j=0;j<frogs-1;j++)
{
if(a[j]==p1){
if(a[j+1]-a[j]<=distance){ m=a[j+1]; if(m==p2)
{System.out.println("Yes");break;}}
else{System.out.println("No");break;}
}
I tried running it on my machine and it runs just fine for any input. gives errors when input is wrong and gives right answers as far as i’ve seen. can some1 point out the mistake in this please or the test cases for which my method fails. it took me about 6 hours to do this , since am new to java . Can some1 help me please… Thanks
I copied the original array A into another array B and sorted it in increasing order, while maintaining the index.Then I copied the elements which fail the condition mentioned.
Please tell me why am I getting SIGSEGV so many times.
I used a 2D vector info with representation as info[i][0]:x-coordinate info[i][1]:index of the frog info[i][2]:con variable i.e. if two frogs have same con then they are connected and can talk.Then I sorted this vector by the x-coordinate(ascending) and then I clustered them according to the condition that two adjacent frogs are in different cluster if their distance is more than K,then I created an array with element at index i being con of ith frog and then checked the input and if they have same con,“yes” else “no”.I am continuously getting SIGSEGV even as the given test case and few other give right answer.I have tried declaring the vector as global variable but that doesn’t help.Please tell me why am I getting SIGSEGV. I would be really thankful.Here’s the link : CodeChef: Practical coding for everyone