RLCIPHER - Robert Langdon & Cipher
Robert and Sienna are running, with Florence police catching up fast. They make a swift left, and found a shallow alley, with a strange looking metal gate at the end. Their only way out : open the gate.
The gate has a horizontal bar, with N sections on it. Each section has an input portal, and a number written below that portal. They have to enter correct number at each portal to open the gate.
The hint given below the portals :
"Take out three, take out four,
Below the voids, take no more.
Tire your brain, let the blood flow,
Plunge it deepest, let it go."
Robert figured : For each section, keep subtracting 3 or 4 from the number written in that section, till the number becomes negative. Try to get the smallest number possible using these operations. Then enter the number in that portal.
They entered the numbers and quickly got in. Can you guess what they answered?
First line contains T, number of test cases. Then each test case contains two lines.
First line of each test case contains N, the number of sections on the horizontal bar.
Second line contains N space separated numbers, containing the numbers on the N sections.
For each testcase, output one line of N space separated number, containing the numbers that must be entered in the portals to get the gate open.
0 2 1
3 2 1 -1
-4 -2 -3
-4 -2 -3 -1
Sum of all N's in a test file will not exceed 105
Each number in each section is between -109 to +109 inclusive.
easiest problem i had ever solved
solution in O(1)
It's strange, I didn't follow the output format and still got AC! What a day :) !
After solving this problem, i am sherlocked. :-)
Really enjoyed it's thinking part....!! Beautiful problem... :)
@ admin here are we supposed to give answers after the whole test case or along with the number scanned?
@Piyush Kumar- please could you check solution ID 10941030? am getting correct answer for all inputs but i think the output(spaces and new line) is getting me WA! :( thanx in advance..