DEFACING - Editorial

My code is resulting in wrong answer …

http://www.codechef.com/viewsolution/1775055

I have tried every test case given in posts and problem…
working correctly…

what is that I am missing ?

what is with initial values of prefix_equal and prefix_less??

http://ideone.com/VRvkWc
this is my code for the problem.It is returning correct solution for every test case(mentioned).
Someone please tell me what is wrong with this because every time I submit it shows wrong answer

The only correct solution posted by me is copied.

I have written my code for this problem. Can you please tell me whats the format of the program. I mean it is not specified how the input will be taken and how the output should.
My code read the file which is in the folder of compiler and gives output in a file. But tester going to know this. He have to change the name of the file according to his testing computer.

So please help me out. How the submission is done.
Thanks in advance.

@syker, you have to perform all the IO from/to stdin/stdout. Just like the normal way you code.
You can check few samples by going on anyone’s profile page and then hitting any problem and then the corresponding solution.

1 Like

@anton_lunyov
Excellent problem…my first attempt at codechef and I am enjoying every bit of it. :slight_smile:

This is the latest version of solution I have developed:
http://www.codechef.com/viewsolution/1864293

It gives a correct output for all the 12 test cases given in problem, 9 tricky cases added by you plus two more given in other comments.

I know, it doesnt mean it is a correct solution but I am unable to understand why I am still getting wrong answer.

I have used my own logic, havent looked at your solution yet, I want to figure out the entire solution on my own. Can you can provide some more test cases, which will help me in figuring out the bug on my own. I tried to create test cases on my own, by using random number generator and all, but got correct answers for all of them. So, if you have some more test cases, it will be great

P.S. : I dont expect you to go through my code as it can be tricky to understand the logic :stuck_out_tongue:

@syker >> Try these tests:

8 13

8 24

Correct Answer: 8 and 18 respectively

Your answer: 89 and 89

UPD.
Your code gives correct answer for the above tests when they are performed initially, but gives 89 when they are written after some tests like 10 100. That might be because of faulty/misplaced initialization of some check arrays.

@anton_lunyov
I am now struggling with TLE issue for this problem.

What I find odd is: time limit is the same irrespective of platform. Isn’t some languages faster as compared to others? And I haven’t seen a single successful submission for JAVA for this problem. I know, it could be a mere coincidence but it still makes me wonder.

I have tried many optimization techniques but none of them are giving any improvements. On my system I see lot of improvements with every major optimization(I have simulated huge inputs, as per given constraints, using random number generators)but when I submit here, I don’t see any improvement at all in time, every time i just get 4.04 seconds, not even slightest improvement.

Moreover, some optimization techniques which definitely should have worked have actually deteriorated the performance, e.g. if you compare the submissions:
CodeChef: Practical coding for everyone and
CodeChef: Practical coding for everyone

the only change is in the function convertToNumber(), where instead of using String object, to append digits one by one, I used StringBuilder and append() function, which according to me should give better performance, but instead the time deteriorated to 10 seconds from 4 seconds.

Any pointers in this regard?

Why is the answer for 25, 100 is 89 but not 98 ?

025 —> 089 —> 89

250 —> 098 —> 98

Somebody please clarify, I’m struggling…

I posted my code on Ideone: tJKTyy - Online C Compiler & Debugging Tool - Ideone.com
I am getting a WA.

I think it is passing the test cases given in the question and the comments here (as well as some ones I made myself), but I might simply be misreading. Can someone help me find my problem? Or at least a test case where my program is returning the wrong answer?

Here there can be leading zeroes in the answer to make S contain the same number of digits as M.
So S can be 089 and the 0 can be removed while printing.

Yes, sameer47 is correct. Here I allowed leading zeros in the solution as the length of the resulting number is not greater than |M|, so it is safe. But thanks I will update the statement.

Fixed. Thanks.

Fixed. Thanks.

You print nothing for this test: 0 6

Refer to this:
http://discuss.codechef.com/answer_link/5641/

http://ideone.com/qgYrei

you can check the link. My program prints 0 for this test case.
and it is giving correct answers for all the test cases posted below

Yes, your bug is quite tricky. It is a big luck that our test data was managed to cover it. Try this test:
2
10381 16146
0 6
I know the reason but I guess you will have a lot of fun by figuring it out the bug by yourself.

Just to make sure that this time I am correct I ideoned your code against this test and it indeed prints nothing for 0 6 now.

where K and M should be prime to each other. :stuck_out_tongue:

I just want to kick myself.
had the fastest solution but could not find the mistake after spending 2 hours on it during the contest