fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Code by : toshit3q34
  5.  
  6. int row_solve(vector<int> vect)
  7. {
  8. int ans = 0;
  9. for (int i = 0; i < 3; i++)
  10. {
  11. if (vect[i] != 0)
  12. {
  13. if (vect[i + 1] == vect[i])
  14. {
  15. vect[i + 1] = 2 * vect[i];
  16. vect[i] = 0;
  17. }
  18. else if (vect[i + 1] == 0)
  19. {
  20. vect[i + 1] = vect[i];
  21. vect[i] = 0;
  22. }
  23. }
  24. }
  25.  
  26. for (int i = 0; i < 4; i++)
  27. {
  28. if (vect[i] == 0)
  29. {
  30. ans++;
  31. }
  32. }
  33. return ans;
  34. }
  35.  
  36. int main()
  37. {
  38. ios::sync_with_stdio(0);
  39. cin.tie(0);
  40.  
  41. int arr[4][4];
  42. for (int i = 0; i < 4; i++)
  43. {
  44. for (int j = 0; j < 4; j++)
  45. {
  46. cin >> arr[i][j];
  47. }
  48. }
  49.  
  50. char c;
  51. cin >> c;
  52.  
  53. vector<int> new_arr[4];
  54. for (int i = 0; i < 4; i++)
  55. {
  56. vector<int> vect(4);
  57. new_arr[i] = vect;
  58. }
  59.  
  60. if (c == 'R')
  61. {
  62. for (int i = 0; i < 4; i++)
  63. {
  64. for (int j = 0; j < 4; j++)
  65. {
  66. new_arr[i][j] = arr[i][3 - j];
  67. }
  68. }
  69. }
  70. else if (c == 'L')
  71. {
  72. for (int i = 0; i < 4; i++)
  73. {
  74. for (int j = 0; j < 4; j++)
  75. {
  76. new_arr[i][j] = arr[i][j];
  77. }
  78. }
  79. }
  80. else if (c == 'D')
  81. {
  82. for (int i = 0; i < 4; i++)
  83. {
  84. for (int j = 0; j < 4; j++)
  85. {
  86. new_arr[i][j] = arr[j][i];
  87. }
  88. }
  89. }
  90. else
  91. {
  92. for (int i = 0; i < 4; i++)
  93. {
  94. for (int j = 0; j < 4; j++)
  95. {
  96. new_arr[i][j] = arr[3 - j][i];
  97. }
  98. }
  99. }
  100.  
  101.  
  102. int ans = 0;
  103. for (int i = 0; i < 4; i++)
  104. {
  105. ans += row_solve(new_arr[i]);
  106. }
  107. cout << ans << '\n';
  108. }
Success #stdin #stdout 0.01s 5216KB
stdin
2 4 8 16
2 4 2 2
2 2 4 4
2 64 32 0
L
stdout
4