Many people got AC with O(nlogn) algorithm just by using faster io. This should not have happened after the author had written the statement “Please try to write a very efficient algorithm and implementation.”
It isn’t a good idea to use very tight limits in such cases, since it’s easy to make efficient solutions fail and inefficient ones pass.
A better approach would be to make the problem interactive in some way, or pack it into something more complex that’d require e.g. a higher degree of log for basic sorting.
My java submission not getting aced.Its giving an NZEC runtime error.The same happened with my python submission.I guess there are unnecessary spaces in input.
JAVA SOLUTION : link
PYTHON SOLUTION : link
But the same idea in C++ getting aced.
C++ SOLUTION : link
THE AUTHOR’S SOLUTION IS WRONG.
It fails for the test case 3 1 2.
According to Author’s solution, after the swaps the elements become 1 2 3, which is in sorted order and prints YES, but the number 3 is 2 places away from its position.
Test case are weak
people passed with code like insertion sort with only one swap(which is incorrect)
Running insertion sort with checks
for more than one swap worked too.Insertion sort runs in almost O(n) for
partially sorted arrays and if you
break when the array is not partially
sorted, the entire code is around O(n)
These kind of code fails with input like:
5
5 1 2 3 4
or
5
1 4 2 3 5
etc
@admin look into this
why my program is not getting accepted its getting tle
can anyone help me through this?
https://www.codechef.com/viewsolution/8591937
@sashi jey, ans for 1 5 8 is yes but yours soln will show no.
For Tle, use scanf printf and “\n”…
https://www.codechef.com/viewsolution/8603936
This is my solution.Please help , I am getting wrong answer.
Also I saw a correct solution , with a condition [ if(A[i-2]>A[i]) >>>> cout<<“NO”; Flag=1;break;] .
Cant understand why it works , since it gives 4 1 5 2 as Yes where as 4 and 2 are clearly off by 2 positions.
Thanks for help]
Many other solutions are bugged. So dont’ trust them
Your code fails for the following case:
1
5
1 0 4 2 5
This is funny. I had never seen a problem with so many incorrect solutions being accepted…
CodeChef: Practical coding for everyone.
Getting WA,
Unable to identify the error. Can someone help?
The idea with your algo is ok, but you have a problem with your iteration.
When you break your iteration on “i”, you don’t read the remaining values. So next time you iterate on “t” you read incorrect values.
Try for instance with the following input.
2
5
10 100 11 12 13
5
1 2 3 5 4
@beroul You provided cases which includes test cases as this-
1
5
1 0 4 2 5
But as mentioned in constraints 1 <= a[i] <= 10^9
. 0
cannot be a valid input for a[i]
.
Check the way you read the data…
See here an example where your code fails:
Sorry. Your code is wrong.
It fails with:
1
6
1 10 2 11 3 14
I don’t check why you get TLE, but your algo is wrong. You check the values against {1,2,3…,n}, but it is not said that the Ai are a permutation of {1,…n}.