Problem p00774 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

int h;
int map[11][6];

int main() {
  int num = 1;

  while (cin >> h) {
    if (h == 0)
      break;
    // cout<<"--------------------"<<num<<"-----------------------"<<endl;
    // num++;
    memset(map, 0, sizeof(map));
    for (int i = 10 - h + 1; i < 11; i++) {
      for (int j = 0; j < 5; j++) {
        cin >> map[i][j];
      }
    }

    int point = 0;
    bool update = true;
    /*
    for(int i = 0;i<10;i++){
      for(int j = 0;j<5;j++){
        cout<<map[i][j]<<"\\t";
      }
      cout<<endl;
    }
    */
    while (update) {
      update = false;
      for (int i = 10 - h + 1; i <= 10; i++) {
        int tmp = 1;
        for (int j = 1; j < 6; j++) {
          if (j != 5 && map[i][j] == 0)
            continue;
          if (map[i][j] == map[i][j - 1]) {
            tmp++;
          } else if (tmp >= 3) {
            point += tmp * map[i][j - 1];

            update = true;
            for (int k = j - tmp; k < j; k++) {
              for (int l = i; l >= 0; l--) {
                map[l][k] = map[l - 1][k];
              }
            }
            tmp = 0;
          } else {
            tmp = 1;
          }
        }
      }
      /*
      cout<<"--------------------------"<<endl;

    for(int i = 0;i<10;i++){
      for(int j = 0;j<5;j++){
        cout<<map[i][j]<<"\\t";
      }
      cout<<endl;
      }

      */
    }
    cout << point << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

int h;
int map[10][6];
bool checked[10][5];

/*
int check(int x,int y,int num,int count){
  if(x > 4)
    return count;

  if(num != map[y][x])
    return count;

  if(count > 5)
    return count;

  if(num == 0)
    return count;

  checked[y][x] = true;
  return check(x+1,y,map[y][x],count+1);
}
*/
int main() {

  while (cin >> h) {
    if (h == 0)
      break;

    memset(map, 0, sizeof(map));
    memset(checked, false, sizeof(checked));

    for (int i = 10 - h; i < 10; i++) {
      for (int j = 0; j < 5; j++) {
        cin >> map[i][j];
      }
    }

    int point = 0;
    bool update = true;
    /*
    for(int i = 0;i<10;i++){
      for(int j = 0;j<5;j++){
        cout<<map[i][j]<<"\\t";
      }
      cout<<endl;
    }
    */
    while (update) {
      update = false;
      // memset(checked,false,sizeof(checked));
      for (int i = 10 - h; i < 10; i++) {
        int tmp = 1;
        for (int j = 1; j < 6; j++) {
          if (j != 5 && map[i][j] == 0)
            continue;
          if (map[i][j] == map[i][j - 1]) {
            tmp++;
          } else if (tmp >= 3) {
            point += tmp * map[i][j - 1];

            update = true;
            for (int k = j - tmp; k < j; k++) {
              for (int l = i; l > 0; l--) {
                map[l][k] = map[l - 1][k];
              }
            }
            tmp = 0;
          } else {
            tmp = 1;
          }
        }
      }
      /*
      cout<<"--------------------------"<<endl;

    for(int i = 0;i<10;i++){
      for(int j = 0;j<5;j++){
        cout<<map[i][j]<<"\\t";
      }
      cout<<endl;
      }

      */
    }
    cout << point << endl;
  }

  return 0;
}