fork download
  1. //code by whatu
  2.  
  3. #include <iostream>
  4. #include <sstream>
  5. #include <string>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. #define FOR(i, k, n) for(i=(int)(k);i<(int)(n);i++)
  11.  
  12. void Run(vector<string> &in, int maxT, vector<bool> &live) {
  13. int i, j;
  14. FOR(j, 0, maxT) {
  15. int all = 0;
  16. FOR(i, 0, in.size()) {
  17. if (!live[i])continue;
  18. if (all == 7)break;
  19.  
  20. if (in[i][j] == 'R' && !(all & 4)) all ^= 4;
  21. else if (in[i][j] == 'S' && !(all & 2)) all ^= 2;
  22. else if (in[i][j] == 'P' && !(all & 1)) all ^= 1;
  23. }
  24. switch (all) {
  25. case 3: {
  26. FOR(i, 0, in.size()) {
  27. if (!live[i])continue;
  28. if (in[i][j] == 'P') live[i] = false;
  29. }
  30. }break;
  31. case 5: {
  32. FOR(i, 0, in.size()) {
  33. if (!live[i])continue;
  34. if (in[i][j] == 'R') live[i] = false;
  35. }
  36. }break;
  37. case 6: {
  38. FOR(i, 0, in.size()) {
  39. if (!live[i])continue;
  40. if (in[i][j] == 'S') live[i] = false;
  41. }
  42. }break;
  43. case 1:
  44. case 2:
  45. case 4:
  46. case 7:continue;
  47. }
  48. }
  49. return;
  50. }
  51.  
  52. int main() {
  53. stringstream answer;
  54. int t;
  55. cin >> t;
  56.  
  57. while (t--) {
  58. int i, n, tR = 0, winner = -1;
  59. vector<string> input;
  60. vector<bool> alive;
  61.  
  62. cin >> n;
  63. input.resize(n);
  64. alive.resize(n);
  65.  
  66. FOR(i, 0, n) {
  67. cin >> input[i];
  68. alive[i] = true;
  69. if (tR < input[i].length())
  70. tR = input[i].length();
  71. }
  72.  
  73. FOR(i, 0, n)
  74. while (input[i].length() < tR)
  75. input[i].push_back('P');
  76.  
  77. Run(input, tR, alive);
  78.  
  79. FOR(i, 0, n) if (alive[i]) {
  80. if (winner == -1) winner = 1 + i;
  81. else { winner = 0; break; }
  82. }
  83. answer << winner << endl;
  84. }
  85. cout << answer.str();
  86. return 0;
  87. }
Runtime error #stdin #stdout #stderr 0s 3476KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_default_append