Well, the problem states that every red marble should only have green marbles in four adjacent cells. Yes, problem doesnt mention chess board, but as i identified the pattern, i saw it similar to chess board. Where a white cell always has four black adjacent cells and same for black cells.
I mentioned chess board to make myself entirely clear.
Often you would find thatwhenever there are 1e5 test case, you need to answer test cases in O(1) or atmost O(logN) time. For that, it’s very often you preprocess all answers, or enough to find all answers.
First, you were not reading all the input lines. You were just reading the first line. Try putting a loop and break the loop at the end of the input file.
Second, you have commented out a portion of your solution from line 5-18
Well, it is not always necesaary that you need to preprocess the answer. Rather, take CHEFUNI of current long challenge. It too require O(1) answer, because T upto 1e5. But in that problem, we cannot even store or calculate answers for all possible values of X, Y Z, A,B and C.
Well, preprocessing often is easier but have time and memory constraints. If preprocessing is feasible with given constraints, go with preprocessing, else prefer constant time solutions (comparatively tougher than preprocessed solution as i feel).
Got it!.
I was doing it only for the first line.And after I got a wrong answer, I commented the code to atleast get the 1st subtask right.Which again failed coz i was just processing first line.
and then you doing this a[i][j] you didn’t initialize a 2d array and as taran said try to separate the for loops when getting the input and solving the problem
yeah ,i got the answer for both the above methods.but i had not used any extra space for creating a 2D array(for the above two cases) but used a single variable which can optimise the solution.but it didnt get accecpted