fork download
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4.  
  5. int t;
  6. int n;
  7. int m;
  8.  
  9.  
  10. bool puedeCambiar(vector<int> p)
  11. {
  12. for (int i = 0;i < p.size();i++)
  13. {
  14. if (p[i] > 1)return 1;
  15. }
  16. return 0;
  17. }
  18.  
  19. bool puedenCambiar(vector<vector<int> > jugadores)
  20. {
  21.  
  22. for (int i = 0;i < n;i++)
  23. {
  24.  
  25. for (int j = 0;j < jugadores[i].size();j++)
  26. {
  27. if (jugadores[i][j] > 1)return 1;
  28. }
  29. return 0;
  30. }
  31.  
  32. }
  33.  
  34. int contar(vector<int> p)
  35. {
  36. int s = 0;
  37. for (int i = 0;i < p.size();i++)
  38. {
  39. if (p[i] >0)return s++;
  40. }
  41. return s;
  42. }
  43.  
  44. int main()
  45. {
  46. cin >> t;
  47. while (t--)
  48. {
  49. cin >> n;
  50. cin >> m;
  51. vector<vector<int> > jugadores;
  52. for (int i = 0;i < n;i++)
  53. {
  54. jugadores.push_back(vector<int>(0));
  55. vector<int>stickers(26, 0);
  56. int cantidad;
  57. cin >> cantidad;
  58. for (int j = 0;j < cantidad;j++)
  59. {
  60. int sticker;
  61. cin >> sticker;
  62. stickers[sticker]++;
  63. }
  64. jugadores[i] = stickers;
  65. }
  66.  
  67.  
  68.  
  69. while (puedeCambiar(jugadores[0]) && puedenCambiar(jugadores)) {
  70.  
  71.  
  72. for (int j = 0;j < jugadores[0].size();j++)
  73. {
  74. for (int h = 1;h < n;h++)
  75. {
  76. for (int k = 0;k < jugadores[h].size();k++)
  77. {
  78. if (jugadores[0][j] > 1 && jugadores[h][j] == 0 && jugadores[h][k] > 1 && jugadores[0][k] == 0)
  79. {
  80. jugadores[0][j]--;
  81. jugadores[h][j]++;
  82. jugadores[0][k]++;
  83. jugadores[h][k]--;
  84. }
  85. }
  86. }
  87.  
  88. cout << endl;
  89. }
  90. }
  91. cout << contar(jugadores[0]) << endl;
  92.  
  93. /* for (int i = 0;i < n;i++)
  94. {
  95.  
  96. for (int j = 0;j<jugadores[i].size();j++)
  97. {
  98. cout << jugadores[i][j] << " ";
  99. }
  100. cout << endl;
  101. }*/
  102.  
  103. }
  104.  
  105. return 0;
  106. }
Runtime error #stdin #stdout 0.07s 4508KB
stdin
1
2 5
6 1 1 1 1 1 1
3 1 2 2
stdout