Need help with Google Code Jam Round 1C Problem A

codejam
gcj

#1

Can anyone explain the solution of Problem 1(Robot Programming Strategy).

I have done exactly mentioned in analysis. First stored all the program of other robots in vector . Then accessed i-th character of all robot and put it in a set. Then I have checked for 3 cases.

  • If set size is 3 (R,P,S) it mean there cannot be any solution with our program can win.

  • If size of set is 1 it means that iteration only have 1 value and we can choose corresponding winning value and return the solution

  • If size of set is 2 then choose the stronger character (like “R” in “RS”) and proceed till we get size of set 3 or 1 , or our program length reaches 500 .

Here is my solution https://ideone.com/KJ8ovE It would be so grateful if anyone can help me debugging the solution.I have tried downloading working solution of other and tried random test cases but it is working fine.


#2

Try this test case :
4
1
P
PR
SP
SRP

It should give SPR as output but your code is giving impossible.


#3

Strange same code giving different output on different ide. I ran on hackerrank it is giving SPR. On ideone/codechef it is giving IMPOSSIBLE


#4

Here is my solution https://ideone.com/EOl10u


#5

Damn me. Got my mistake.
set ch;
char curr[501];
int i = 0;
for (auto xx : ch) {
curr[i++] = xx;
}
//curr[i] = ‘\0’; Missed to introduce this terminater.
string cur(curr);

Learning : We should always take care of basics.


#6

hey do you qualified for round 2


#7

No . I was unable to debug above silly mistake.


#8

No problem same story here…I just forget to stop checking for strings which are knocked out…


#9

Yes , I have qualified for round 2


#10

Congrats . What was your rank?