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

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  while (1) {
    int a, b, c, x[11];
    vector<int> vec;
    scanf("%d", &a);
    scanf("%d", &b);
    if (a == 0) {
      break;
    }
    for (int i = 0; i < a; i++) {
      scanf("%d", &x[i]);
    }
    if (b == 2) {
      for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
          if (j != i) {
            if (x[j] >= 10) {
              vec.push_back(x[i] * 100 + x[j]);
            } else {
              vec.push_back(x[i] * 10 + x[j]);
            }
          }
        }
      }
    } else if (b == 3) {
      for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
          if (j != i) {
            for (int k = 0; k < a; k++) {
              if (k != i) {
                if (k != j) {
                  if (x[k] >= 10) {
                    if (x[j] >= 10) {
                      vec.push_back(x[i] * 10000 + x[j] * 100 + x[k]);
                    } else {
                      vec.push_back(x[i] * 1000 + x[j] * 100 + x[k]);
                    }
                  } else {
                    if (x[j] >= 10) {
                      vec.push_back(x[i] * 1000 + x[j] * 10 + x[k]);
                    } else {
                      vec.push_back(x[i] * 100 + x[j] * 10 + x[k]);
                    }
                  }
                }
              }
            }
          }
        }
      }
    } else if (b == 4) {
      for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
          if (j != i) {
            for (int k = 0; k < a; k++) {
              if (k != i) {
                if (k != j) {
                  for (int h = 0; h < a; h++) {
                    if (h != i) {
                      if (h != j) {
                        if (h != k) {
                          if (x[h] >= 10) {
                            if (x[k] >= 10) {
                              if (x[j] >= 10) {
                                vec.push_back(x[i] * 1000000 + x[j] * 10000 +
                                              x[k] * 100 + x[h]);
                              } else {
                                vec.push_back(x[i] * 100000 + x[j] * 10000 +
                                              x[k] * 100 + x[h]);
                              }
                            } else {
                              if (x[j] >= 10) {
                                vec.push_back(x[i] * 100000 + x[j] * 1000 +
                                              x[k] * 100 + x[h]);
                              } else {
                                vec.push_back(x[i] * 10000 + x[j] * 1000 +
                                              x[k] * 100 + x[h]);
                              }
                            }
                          } else {
                            if (x[k] >= 10) {
                              if (x[j] >= 10) {
                                vec.push_back(x[i] * 100000 + x[j] * 1000 +
                                              x[k] * 10 + x[h]);
                              } else {
                                vec.push_back(x[i] * 10000 + x[j] * 1000 +
                                              x[k] * 10 + x[h]);
                              }
                            } else {
                              if (x[j] >= 10) {
                                vec.push_back(x[i] * 10000 + x[j] * 100 +
                                              x[k] * 10 + x[h]);
                              } else {
                                vec.push_back(x[i] * 1000 + x[j] * 100 +
                                              x[k] * 10 + x[h]);
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    sort(vec.begin(), vec.end());
    int ans = 1;
    for (int i = 0; i < vec.size() - 1; i++) {
      if (vec[i] != vec[i + 1]) {
        ans++;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  while (1) {
    int a, b, c, x[11];
    vector<int> vec;
    scanf("%d", &a);
    scanf("%d", &b);
    for (int i = 0; i < a; i++) {
      scanf("%d", &x[i]);
    }
    if (b == 2) {
      for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
          if (j != i) {
            if (x[j] >= 10) {
              vec.push_back(x[i] * 100 + x[j]);
            } else {
              vec.push_back(x[i] * 10 + x[j]);
            }
          }
        }
      }
    } else if (b == 3) {
      for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
          if (j != i) {
            for (int k = 0; k < a; k++) {
              if (k != i) {
                if (k != j) {
                  if (x[k] >= 10) {
                    if (x[j] >= 10) {
                      vec.push_back(x[i] * 10000 + x[j] * 100 + x[k]);
                    } else {
                      vec.push_back(x[i] * 1000 + x[j] * 100 + x[k]);
                    }
                  } else {
                    if (x[j] >= 10) {
                      vec.push_back(x[i] * 1000 + x[j] * 10 + x[k]);
                    } else {
                      vec.push_back(x[i] * 100 + x[j] * 10 + x[k]);
                    }
                  }
                }
              }
            }
          }
        }
      }
    } else if (b == 4) {
      for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
          if (j != i) {
            for (int k = 0; k < a; k++) {
              if (k != i) {
                if (k != j) {
                  for (int h = 0; h < a; h++) {
                    if (h != i) {
                      if (h != j) {
                        if (h != k) {
                          if (x[h] >= 10) {
                            if (x[k] >= 10) {
                              if (x[j] >= 10) {
                                vec.push_back(x[i] * 1000000 + x[j] * 10000 +
                                              x[k] * 100 + x[h]);
                              } else {
                                vec.push_back(x[i] * 100000 + x[j] * 10000 +
                                              x[k] * 100 + x[h]);
                              }
                            } else {
                              if (x[j] >= 10) {
                                vec.push_back(x[i] * 100000 + x[j] * 1000 +
                                              x[k] * 100 + x[h]);
                              } else {
                                vec.push_back(x[i] * 10000 + x[j] * 1000 +
                                              x[k] * 100 + x[h]);
                              }
                            }
                          } else {
                            if (x[k] >= 10) {
                              if (x[j] >= 10) {
                                vec.push_back(x[i] * 100000 + x[j] * 1000 +
                                              x[k] * 10 + x[h]);
                              } else {
                                vec.push_back(x[i] * 10000 + x[j] * 1000 +
                                              x[k] * 10 + x[h]);
                              }
                            } else {
                              if (x[j] >= 10) {
                                vec.push_back(x[i] * 10000 + x[j] * 100 +
                                              x[k] * 10 + x[h]);
                              } else {
                                vec.push_back(x[i] * 1000 + x[j] * 100 +
                                              x[k] * 10 + x[h]);
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    sort(vec.begin(), vec.end());
    int ans = 1;
    for (int i = 0; i < vec.size() - 1; i++) {
      if (vec[i] != vec[i + 1]) {
        ans++;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}