DYEL - Do You Even Lift
Summer's coming up in a few months, so you decide to hit the gym to put on some muscle. When you arrive, you're confronted with dozens of machines, free weights, barbells, stationary bikes and more. All of this is quite confusing to a newcomer, so you just stand there confused, checking your cellphone a few times, and leave.
After this less-than-stellar experience, you decide to do some research online. You learn that people train in things called "programs", which are instructions to determine how much weight to lift on a particular day. These are always of the form "Lift twice what you lifted three days ago, plus three times what you lifted 7 days ago", or similar. In general, such a "program" tells you that the weight you need to lift today is some combination of the weights you've lifted previously. The program also gives you some initial weights, for when the formula doesn't make sense.
Being very clever, however, you decide that the advice you find during your research is for suckers. You won't even bother with known programs like Starting Strength, StrongLifts 5x5, or even CrossFit. What you'll do is much cleverer: You'll go to the gym, find the most jacked bro in there, and imitate his program. To figure out his program, you'll record what he lifts each day he goes to the gym, for a few days.
Since you are lazy, of all the possible programs he could be following which would match your observations, you want only the shortest one (the one that mentions as few days back as possible). Can you find it?
Input
The input consists of multiple test cases, and starts with a positive integer T. T test cases follow.
Each test case starts with a number K, the number of days you've watched the bro lift weights for. After that come K nonnegative integers W_i, denoting the weight he lifted each day, from oldest lifts to most recent ones. You are assured that the bro is indeed following a program.
Output
For each test case, output a single line, consisting of N space separated non-negative integers D_i, if the program says each day you should lift the sum of (D_i times the weight you lifted i days ago), for 1 ≤ i ≤ N. N is the length of the shortest solution you found and should not be printed
Example
Input: 5 10 48 64 96 128 192 256 384 512 768 1024 8 3 3 2 25 136 782 4479 25659 8 3 3 24 87 381 1578 6639 27807 14 3 3 1 2 4 8 16 32 64 128 256 512 1024 2048 8 16909 42737 110373 281321 722813 1848097 4739349 12131737 Output: 0 2 5 4 1 3 5 2 0 0 1 4
Constraints
hide comments
[Rampage] Blue.Mary:
2016-03-11 06:32:41
Warning: "Warning: You may need to use very big integers." is very misleading. This problem can be solved using only singed/unsigned 64-bit integers in C. In other words, the key to solve this problem is how to avoid big integer arithmetic. Last edit: 2016-03-11 08:35:47 |
|
Federico Lebrón:
2013-09-02 02:51:35
Because if it were "2", then since we have "3 3 1", it would need to happen that 3 = 3 * 2, and 1 = 3 * 2". In the program "2", the only thing that can follow a 3 is 6. |
|
mehmetin:
2013-09-02 02:51:35
Why the output for the fourth case isn't just "2"? |
|
:D:
2013-09-02 02:51:35
I have no idea what the intended solution was, but the way I did it, I see it as a really great problem. Learned quite a few new things. Many thanks for putting it on SPOJ. |
Added by: | Federico Lebron |
Date: | 2013-08-04 |
Time limit: | 0.5s-6s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Federico Lebrón |