I need a help wrt the below problem statement:
Each cell of an N x N grid is either a 0 or a 1. You are given two such N x N grids, the initial grid and the final grid. There is a button against each row and each column of the initial N x N grid. Pressing a row-button toggles the values of all the cells in that row, and pressing a column-button toggles the values of all the cells in that column. You are required to find the minimum number of button presses required to transform the grid from the initial configuration to the final configuration, and the buttons that must be pressed in order to make this transformation. Edit: When the initial and the final configurations are the same, print "0". Input
The first line contains t, the number of test cases (about 10). Then t test cases follow.
Each test case has the following form: * The first line contains n, the size of the board (1 ≤ n ≤ 1000). * n lines follow. The ith line contains n space separated integers representing the ith row of the initial grid. Each integer is either a 0 or a 1. * n lines follow, representing the final grid, in the same format as above. Output For each test case, output the number of row-button presses, followed by the row buttons that must be pressed. Print the number of column-button presses next, followed by 0-indexed indices of the column buttons that must be pressed. The total number of button presses must be minimized. Output "-1" if it is impossible to achieve the final configuration from the initial configuration. If there is more than one solution, print any one of them.
Input: 1 3 0 0 0 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1
Output: 1 0 1 2
I have uploaded the code as an attachment named with this topic : toggle2.cpp
Though it works absolutely fine on my machine,it doesnt accept a solution at codechef and gives me a wrong answer.Can anyone guide me what to do pls pls pls??Am i going wrong somewhere with respect to the logic or its something else?
Code has been written in C++ and compiled using g++ compiler.
Any help would be deeply appreciated ppl Thanking in advance
I downloaded, compiled and ran your code with your input. Appart from the interface being a bit cryptic, it ran fine, and gave the expected output.
I'm using CodeBlocks MinGW on a Win32 machine.
I looked through your code, and saw nothing wrong.
I didn't get any warnings either, and I had -WAll
Apart from that, I don't know what to say, you don't say much other than "it doesn't work"... What is your problem? Compile? Crashes? Wrong result?
I suppose your algorithm is some kind of Gaussian elimination algorithm? This is fine because the algorithm is simple and deterministic, but it fails to respect the "The total number of button presses must be minimized" condition (I believe).
Thanks so much for ur response.
To get u a detailed scenario,let me tell you its giving me a WRONG ANSWER.
Regarding the last point which you mentioned about minimizing the no of button presses,i have developed the algo such that from the various possible solutions,it selects the solution which would take least no of button presses.So i dont really think that there may be a problem wrt the minimizing of button presses.