#include #include #include using namespace std; bool lastLine = false; class Character { public: Character(int pos):position(pos){} void moveUp() { position >>= 1; } void moveDownRight() { position <<= 1; position += 1; } void moveDownLeft() { position <<=1; } int getPosition() { return position; } private: int position; }; bool bugsIsDead(Character& bugs, vector& elmers, int moveCount) { for (int i = 0; i < elmers.size(); i++) { if (elmers[i].getPosition() == bugs.getPosition()) { cout << moveCount << " " << i + 1; if (!lastLine) { cout << endl; } return true; } } return false; } void moveCharacter(Character& character, char letter) { switch (letter) { case 'L': character.moveDownLeft(); break; case 'R': character.moveDownRight(); break; case 'U': character.moveUp(); break; default : break; } } bool doMove(string moves, Character& bugs, vector& elmers, int moveCount) { moveCharacter(bugs, moves[0]); if (bugsIsDead(bugs, elmers, moveCount)) { return true; } for (int i = 1; i < moves.size(); i++) { moveCharacter(elmers[i - 1], moves[i]); } return bugsIsDead(bugs, elmers, moveCount); } void simulate(vector& moves, Character& bugs, vector& elmers) { bool bugsBunnyDIES = false; for (int i = 0; i < moves.size(); i++) { if(doMove(moves[i], bugs, elmers, i+1)) { bugsBunnyDIES = true; break; } } if (!bugsBunnyDIES) { cout << 0 << " " << 0; if (!lastLine) { cout << endl; } } } void main () { int N; cin >> N; while (N > 0) { int nElmers; cin >> nElmers; vector elmers; for (int i = 0; i < nElmers; i++) { elmers.push_back(Character(1)); } int nMoves; cin >> nMoves; int bugsPos; cin >> bugsPos; Character bugs(bugsPos); vector moves; for (int i = 0; i < nMoves; i++) { string move; cin >> move; moves.push_back(move); } if (N == 1) { lastLine = true; } simulate(moves, bugs, elmers); N--; } }