Submit | All submissions | Best solutions | Back to list |
PLUS - On the Plus Side |
A man called Gerit Teeman was fascinated by the plus symbol and, to be honest, this symbol is actually quite interesting!
Begin by drawing an one. This will be the center of the plus symbol. Above this center draw the number two, below three, to the left four and the the right five. If you then 'replace' the center (either up, down, left or right), do the same, but when a place is already filled you leave it untouched.
To illustrate this we pick the place with the number two: Above it draw a two, the bottom is already filled so we leave it untouched, to the left we draw a four and the the right we draw a five. See the picture below:
It is not hard to see that the sum of the first plus symbol is 15 (the first symbol only containing 1 is NOT a plus symbol). The sum of the second symbol is already more difficult, summing up to 26. Now here comes the catch: depending on which number you pick to expand on, the number on positions can change. If we would have picked five to expand on instead of two, we will get the following:
As you can see the numbers differ from that of the first example. This time the sum is 25! On top of that, there can be multiple 'replaces', generating more number in the symbol. Your task is, depending on which way you expand to, give the sum of all the elements of plus symbol that you would obtain.
Input
First line contains an integer T (1 <= T <= 100) number of test cases. Each of the next T lines contains a string with letters 'L', 'R', 'U', 'D' and 'S' (separated by commas) which respectively mean left, right, up, down and stop. You should expand to the given direction, based on your last created expansion's center. Stop means you should finish and output the total sum to that point. The number of letters in the string will never exceed 10000.
Note that the first example was created by the string "U,S" and the second by the string "R,S".
Output
For each test case output a single integer in a separate line: the total sum of all numbers contained in the created symbol.
Sample:
Input: 2 U,S S Output: 26 15
Added by: | Laurens |
Date: | 2013-08-12 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Self created problem |
hide comments
|
|||||
2019-11-01 10:09:22 Sushovan Sen
I am really surprised to see only a few had solved the problem. It seems very basic, logic and implementation wise. Last edit: 2019-11-26 05:31:19 |
|||||
2016-08-03 22:50:19
@susiconfusi Thanks :) |
|||||
2016-07-09 22:58:27
@hodobox, the third explanation, to stop processing the string when the first 'S' occurs, seems to be correct. |
|||||
2016-06-21 12:28:31
'S' occurs at different times than at end of string. Don't know if I'm supposed to print result once for the entire string (ignoring 'S'), print answer for all 'S' (sum of current plus), or print answer for first 'S' and' finish and output the total sum to that point'. I get WA for all of the above, although from the few cases in the comments my answers seem ok. Output description mentions one integer per line, which favours either the first or third explanation, but idk. Last edit: 2016-06-21 12:34:33 |
|||||
2013-12-25 16:12:31 tuhin
i swear i have been a dumbfuck . very misleading . i thot the size of the string is maximum 10000. but with the , its double ie 20000 . i have been sitting around for the whole day trying to find a bug when a friend actually pointed my mistake . Spoj can drive u nuts at times :( Last edit: 2013-12-25 17:57:49 |
|||||
2013-08-19 17:31:31 nitish rao
@Tjandra @setter.. shouldn't there be a single 'S' per line? coz u were telling to "finish" and display the sum. If im wrong, then what should be the correct output for "S,L,S"?? I guess it should be 15 followed by 24 as @rohit was pointing. |
|||||
2013-08-14 13:22:52 (Tjandra Satria Gunawan)(曾毅昆)
@rohit kumar: Both of your answer is wrong.. |
|||||
2013-08-13 22:58:58 rohit kumar
what will be the output for S,L,S is output is 15 24 or 24 |
|||||
2013-08-13 11:41:42 (Tjandra Satria Gunawan)(曾毅昆)
@LeppyR64: Thanks for your explanation :-) |
|||||
2013-08-13 11:41:42 LeppyR64
Tjandra: No. Those outputs are for U,R,D,S and R,U,L,S. you have too many numbers in your grid. Also, this is a weird case. 1 S,L,S |