/* Topcoder SRM 709 D2 250-Pointer Robofactory James S. Plank Wed Mar 8 02:25:59 EST 2017 */ #include #include #include #include using namespace std; typedef vector IVec; typedef vector SVec; class Robofactory { public: int reveal(vector query, vector answer); }; int Robofactory::reveal(vector query, vector answer) { int i; int could_be_corrupted; /* Pass one -- if any robots give the wrong answer, return the robot. */ for (i = 0; i < query.size(); i++) { if (query[i] %2 == 0 && answer[i] == "Odd") return i; if (query[i] %2 == 1 && answer[i] == "Even") return i; } /* Pass two -- count the number of robots who could be corrupted. This means that the robot is either robot 0, or the previous robot was given an odd number. */ could_be_corrupted = 0; for (i = 0; i < query.size(); i++) { if (i == 0 || query[i-1]%2 == 0) could_be_corrupted++; } /* If only one robot could be corrupted, it's robot 0. */ if (could_be_corrupted == 1) return 0; /* Otherwise, there are multiple robots that could be corrupted, so you return -1. */ return -1; }