CHEFHACK - Editorial

The editorial is pretty nice.
I wonder what was wrong with my implementation.
Can you please have a look and let me know my error. It would be great. I’m unable to figure out.

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

Nice editorial.
I have an unrelated question though. I used BFS instead of DFS. Everything else was same as you suggested in your editorial. But I was getting Wrong answer somehow.
I tried it with many test cases generated by hand and it was working fine. How should I approach in finding problems in my code in such scenarios.
Any help will be highly appreciated.

BTW, my problem submission was
http://www.codechef.com/viewsolution/1720890

If anyone can point to what test cases my program was failing, it will be really helpful.
Thanks in advance.

only mistake was… i used 32bit integer for total cost instead of 64
feels like kill-me-now

7 Likes

I first used an integer array of size 10e7 for the sieve, but it ran out of memory though…had to half the size of the array and cancel all the even numbers.

What is problem in my solution…
I am getting WA
http://www.codechef.com/viewsolution/1723138

To implement grid hacking in java, if i use an ArrayDeque or a LinkedList, i get TLE( CodeChef: Practical coding for everyone ), while if i change the data structure to ArrayList( CodeChef: Practical coding for everyone ), i get one of the fastest execution times in java. Any reason as to why this is happening?

Thanks for such a detailed editorial. I learnt a lot. But still my program is not getting submitted. If I am not asking too much, can I get a sample test case for which my code is failing. My submission id is 1724659. Thanks.

I had the same solution in Java (except I used the Sieve of Atkin and instead of a boolean[][] I changed the original input array directly), but I kept getting WA :/.

Can somebody check my solution to see what’s wrong? I tried several test cases, but all of them printed out the right answer…

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

Hi,

Actually i did the same solution described above in Python but it didn’t work (i got Time Limit Exceeded), you can check my attempt here and here.

But actually, i was able to find another algorithm for this problem that got accepted, the idea was that i only check for immediate neighbors of any server to know if it should be included or not, of course this may lead to count a server while it shouldn’t (i.e. it should have been already cracked), but to be aware of this case i created a Python dictionary that hold information about which server cracked which one (cracked_by) and then each time i visit a server i check if i should update the cracked_by of the immediate neighbors to know if i added wrongly a server if yes i discard the value from the result.

You can check my solution here, feel free to post any feedback.

HTH,

1 Like

I got AC after using Sieve of Eratosthenes but I want to implement it by another method by which I couldn’t. We can find all prime numbers less than 10^7 by simply making another prime number program and copy the output and assign it to array in our program arr[]={all prime numbers less than 10^7 that we already have.}. Now just apply a for loop
for(i=0;i<arr.size;i++)
arr1[arr[i]]=i;
now just find if any number is a prime by
if(arr1[num]!=0)
return arr1[num];

but In the above approach I couldn’t assign the whole set of prime numbers to arr[] manually by copy paste. I am getting error “/usr/lib/gcc/i486-linux-gnu/4.3.2/…/…/…/…/lib/crt1.o: In function _start': /home/aurel32/tmp/glibc/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference tomain’ collect2: ld returned 1 exit status” when I am submitting my code.

Can the admins tell what’s wrong with CodeChef: Practical coding for everyone?

In other note :- The tester solution is not getting complied on gcc. Need to include stdio.h.

I’m getting WA my solution is this http://www.codechef.com/viewsolution/1742829.

The test data, http://pastebin.com/raw.php?i=j6UWCAZ5
is too large for me to debug the program, so I am unable to find why is it giving 421211088 instead of correct result. Can you please help.
My solution is CodeChef: Practical coding for everyone

i have checked all the test cases which u have provided in the editorial and it gives right answer.I am unable to figure out the problem. CodeChef: Practical coding for everyone

I habe a problem in my solution http://www.codechef.com/viewsolution/1745646 based on the editorial which seems to be more a compiler/c++ problem then an algorithmic problem.
I got the error “Access violation reading location 0x01A4B7A4” when trying to read from my big prime array. Can anyone help?

Please have a look at the following solution :

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

It gave correct results for the test cases mentioned in the editorial here, those in the problem statement and some cases generated by myself. But still it displays ‘Wrong Result’ here.

Please help!

Can you please tell whats wrong with my code…its giving correct output for test cases…

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

my


[1]  is giving a runtime error(NZEC).Can anyone plz tell what is the problem?


  [1]: http://www.codechef.com/viewsolution/1790006

Can anybody look at my solution and explain why am i getting Runtime error(segmentation fault). i cant see why…:frowning:

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

my code runs fine on my machine but shows wrong answer on submission
Please help my solution is here CodeChef: Practical coding for everyone