×

# PROBLEM WITH INTXOR DEC CHALLENGE

 0 can anyone check the logic and say where am i going wrong???? ================here is my code=================== https://www.codechef.com/viewsolution/22036469 thanx in advance!!! :) asked 22 Dec '18, 00:32 2★sabios 1 accept rate: 0%

 0 Why are you using the value of an uninitialised variable n in Line 9 (memset)? Edit -> Whoops! Found the bug! From what I understood from going through your code, you are first checking what the remainder is upon division by 4. Now, if the remainder is 0, we can solve the entire question in chunks of 4. If the remainder is 1, we can the question in chunks of 4 and the last one in chunks of 5. (But we have to be careful not to use up the last chunk of 4 or else we'll be left with a single element). I see that you handled that case well. And so on, just preserving the last 5 or 6 or 7 elements. Now, the problem arises when the remainder is 0. Since the last block of 4 is never used in the while loop (as it could lead to the isolation of 1 or 2 or 3 elements), therefore in the case of remainder 0 too, the last block of 4 is not used. So we need to fill the last block manually again. (Or you can just relax the conditions of the while loop when j==0.) Here's the link to your code which passes all the test cases! https://www.codechef.com/viewsolution/22036772 answered 22 Dec '18, 00:59 106●3 accept rate: 13% yeah bro..jst figured it out.............anyways thanx for such a quick reply....keep up the good work!!!! (22 Dec '18, 11:33) sabios2★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×152
×37
×35

question asked: 22 Dec '18, 00:32

question was seen: 279 times

last updated: 22 Dec '18, 11:33