Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream cin("2048.in");
- ofstream cout("2048.out");
- const int MAX = 10001;
- int v[MAX], n, m, x, y, z;
- int main()
- {
- cin >> n >> m;
- int gata = 0;
- for(int i = 1; i <= n; ++i) {
- cin >> v[i];
- if(v[i] == 2048) {
- gata = 1;
- }
- }
- for(int i = 1; i <= m; ++i) {
- if(gata == 1) {
- break;
- }
- ++x;
- char ch;
- cin >> ch;
- int nf = 0;
- if(ch == 'D') {
- for(int j = n - 1; j >= 1; --j) {
- if(v[j] == v[j + 1]) {
- ++nf;
- v[j + 1] = 2 * v[j + 1];
- v[j] = -1;
- if(v[j + 1] == 2048) {
- gata = 1;
- }
- }
- }
- } else {
- for(int j = 2; j <= n; ++j) {
- if(v[j - 1] == v[j]) {
- ++nf;
- v[j - 1] = 2 * v[j - 1];
- v[j] = -1;
- }
- if(v[j - 1] == 2048) {
- gata = 1;
- }
- }
- }
- if(nf == 0) {
- --x;
- gata = 1;
- }
- if(nf > z) {
- z = nf;
- }
- ///aliniere
- int bune = 0;
- for(int j = 1; j <= n; ++j) {
- if(v[j] != -1) {
- ++bune;
- v[bune] = v[j];
- }
- }
- n = bune;
- }
- for(int i = 1; i <= n; ++i) {
- if(v[i] > y) {
- y = v[i];
- }
- }
- cout << x << '\n' << y << '\n' << z;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement