CHEFHACK - Editorial

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

@anton_lunyov

@i_am_what_i_am

Hi, I just studied DFS and then searched this problem through question tags.
I passed the given test cases and also the cases given in editorial.
But still couldn’t get AC.

I made these solutions:

  1. https://www.codechef.com/viewsolution/8801554 —> It gave me WA

  2. https://www.codechef.com/viewsolution/8801563 —> It gave me RE

The only difference between both these solutions is that i have changed my counter variable which is needed to be printed from long to long long.

I would be so glad if anyone could explain me the bug.

struggling from a day with my code here
it gives correct answer to all cases ever in discussion or editorial but still getting a WA.
help would be greatly appreciated

Hey I solved the problem with same approach as given above but it’s showing wrong answer. Please can anyone help

https://www.codechef.com/viewsolution/14628909

Hey I solved the problem with same approach as given above but it’s showing wrong answer. Please can anyone help

https://www.codechef.com/viewsolution/14628909

Did you test you program at least somehow?
They produce wrong result on any possible test.
I don’t know. Consider for example this one:
1
1
3
The correct answer is 1, while you return -0 (yeah, with this crappy minus sign)

One suggestion is that you should use long long type for unsec and print it as printf("%lld ",unsec).

2 Likes

fantastic editorial. loved it!

are you sure this test case my program give wrong answer because in my computer answer is 1 not -0.are you sure that you check correct submit my program id is:1681905

I’m in the same page :(!

I look here
http://campus.codechef.com/files/stderr/1681905/
Only admins, setter and tester have access to this.
Your answer for 8th test which is very small test is
DATASET NUMBER: 8
-0
-268156158598…
-0
-427197407184…
-125542034707…
-0
-0
-0
where … is some other digits (like hundreds of digits more)
Try to run your code on ideone.com using GNU C++ compiler against this test case.

1 Like

I used BFS as well. I got TLE. :frowning:

same here… :frowning:

@editorialist : great work to give additional links to similar problems :slight_smile: thanks. Things are really changing nicely in new year :slight_smile:

3 Likes

Its Nice…

@sarfarajey Read the bold tip in the beginning of the editorial.

1 Like

Try to use usual array instead of queue.
You could simply have a loop
for(int k=0;k<len;k++)
where len is the total number of added elements to the queue and it will be increased by 1 after adding each new cell.

I think the queue is the real bottleneck of your solution.

1 Like

@vikram535 You have repeated the same mistake as hundreds of contestants and tens of contestants who asking for help after the contest.

You should use 64-bit integer type long long for the answer and output it either using cout or %lld specifier.

Regarding the bfs, see my answer above in the response
http://discuss.codechef.com/answer_link/5181/
In short, you should use usual array instead of queue.

Actually the main your issue is declaring all arrays inside main().
They are stored in a stack which is quite limited and hence you received runtime error.
The displayed memory 1500M is just the bug in codechef system.
The stack size seems to be 32M hence initially you have used 40M and get RE
but then half the size to 20M and all became fine.

Your output for this test
4
0 4 8 12
0 1 9 24
0 1 9 12
0 8 16 18
is 16 while should be 2.