Advertisement
Guest User

Untitled

a guest
May 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4. ifstream cin("2048.in");
  5. ofstream cout("2048.out");
  6. const int MAX = 10001;
  7. int v[MAX], n, m, x, y, z;
  8. int main()
  9. {
  10. cin >> n >> m;
  11. int gata = 0;
  12. for(int i = 1; i <= n; ++i) {
  13. cin >> v[i];
  14. if(v[i] == 2048) {
  15. gata = 1;
  16. }
  17. }
  18. for(int i = 1; i <= m; ++i) {
  19. if(gata == 1) {
  20. break;
  21. }
  22. ++x;
  23. char ch;
  24. cin >> ch;
  25. int nf = 0;
  26. if(ch == 'D') {
  27. for(int j = n - 1; j >= 1; --j) {
  28. if(v[j] == v[j + 1]) {
  29. ++nf;
  30. v[j + 1] = 2 * v[j + 1];
  31. v[j] = -1;
  32. if(v[j + 1] == 2048) {
  33. gata = 1;
  34. }
  35. }
  36. }
  37. } else {
  38. for(int j = 2; j <= n; ++j) {
  39. if(v[j - 1] == v[j]) {
  40. ++nf;
  41. v[j - 1] = 2 * v[j - 1];
  42. v[j] = -1;
  43. }
  44. if(v[j - 1] == 2048) {
  45. gata = 1;
  46. }
  47. }
  48. }
  49. if(nf == 0) {
  50. --x;
  51. gata = 1;
  52. }
  53. if(nf > z) {
  54. z = nf;
  55. }
  56. ///aliniere
  57. int bune = 0;
  58. for(int j = 1; j <= n; ++j) {
  59. if(v[j] != -1) {
  60. ++bune;
  61. v[bune] = v[j];
  62. }
  63. }
  64. n = bune;
  65. }
  66. for(int i = 1; i <= n; ++i) {
  67. if(v[i] > y) {
  68. y = v[i];
  69. }
  70. }
  71. cout << x << '\n' << y << '\n' << z;
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement