Problem p00774 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using Line = vector<char>;
using Puzzle = vector<Line>;

void newline() { cout << endl; }
template <typename T> void put(T input) { cout << input; }
template <typename T> void putl(T input) {
  put(input);
  newline();
}

int n;
int point;
Puzzle puzzle;

void swap_rec(int column, int row) {
  if (0 < column) {
    swap(puzzle[column][row], puzzle[column - 1][row]);
    swap_rec(column - 1, row);
  }
}

void drop() {
  Puzzle prev_puzzle = puzzle;
  for (int column = puzzle.size() - 1; 0 <= column; column--) {
    for (int row = puzzle[column].size() - 1; 0 <= row; row--) {
      if (puzzle[column][row] == '#')
        swap_rec(column, row);
    }
  }
  if (puzzle != prev_puzzle)
    drop();
}

int clear(Line &line, int n, char c) {
  if (line[n] == c) {
    line[n] = '#';
    if (1 <= n && n < line.size() - 1) {
      return int(c) - int('0') + clear(line, n + 1, c) + clear(line, n - 1, c);
    } else {
      return int(c) - int('0');
    }
  } else {
    return 0;
  }
}

int solve() {
  Puzzle prev_puzzle = puzzle;
  for (Line &line : puzzle)
    for (int k = 1; k < line.size() - 1; k++)
      if (line[k] != '#' && line[k - 1] == line[k] && line[k] == line[k + 1])
        point += clear(line, k, line[k]);
  drop();
  if (prev_puzzle != puzzle)
    solve();
  return point;
}

int main() {
  while (cin >> n && n) {
    point = 0;
    puzzle = {};
    puzzle.reserve(n);
    for (int ic = 0; ic < n; ic++) {
      Line line;
      line.resize(5);
      for (int lc = 0; lc < 5; lc++) {
        char s;
        cin >> s;
        line[lc] = s;
      }
      puzzle.push_back(line);
    }
    putl(solve());
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
#define Line vector<char>
#define Puzzle vector<Line>

void newline() { cout << endl; }
template <typename T> void put(T input) { cout << input; }
template <typename T> void putl(T input) {
  put(input);
  newline();
}

int n;
int point;
Puzzle puzzle;

void swap_rec(int column, int row) {
  if (0 < column) {
    swap(puzzle[column][row], puzzle[column - 1][row]);
    swap_rec(column - 1, row);
  }
}

void drop() {
  Puzzle prev_puzzle = puzzle;
  for (int column = puzzle.size() - 1; 0 <= column; column--) {
    for (int row = puzzle[column].size() - 1; 0 <= row; row--) {
      if (puzzle[column][row] == '#')
        swap_rec(column, row);
    }
  }
  if (puzzle != prev_puzzle)
    drop();
}

int clear(Line &line, int n, char c) {
  if (line[n] == c) {
    line[n] = '#';
    if (1 <= n && n < line.size() - 1) {
      return int(c) - int('0') + clear(line, n + 1, c) + clear(line, n - 1, c);
    } else {
      return int(c) - int('0');
    }
  } else {
    return 0;
  }
}

int solve() {
  Puzzle prev_puzzle = puzzle;
  for (Line &line : puzzle)
    for (int k = 1; k < line.size() - 1; k++)
      if (line[k] != '#' && line[k - 1] == line[k] && line[k] == line[k + 1])
        point += clear(line, k, line[k]);
  drop();
  if (prev_puzzle != puzzle)
    solve();
  return point;
}

int main() {
  while (cin >> n && n) {
    point = 0;
    puzzle = {};
    puzzle.reserve(n);
    for (int ic = 0; ic < n; ic++) {
      Line line;
      line.resize(5);
      for (int lc = 0; lc < 5; lc++) {
        char s;
        cin >> s;
        line[lc] = s;
      }
      puzzle.push_back(line);
    }
    putl(solve());
  }
}