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

#include <iostream>
#include <stdlib.h>

#define SHIRO 0
#define USUI 1
#define ATSUI 2

using namespace std;

int l, k;
double array[200];
void print(int *pole) {
  for (int i = 0; i < l; i++)
    printf("%d ", pole[i]);
  printf("\\n");
}

bool check(int *pole, int len) {
  // l ?????????????¶????????????????
  if (l < len)
    return false;
  // ???????????\\?????????
  if (pole[0] == SHIRO)
    return false;
  // ???????????\\?????????
  if (pole[len - 1] == SHIRO)
    return false;
  return true;
}

/* copy array */
void copy(int *tmp, int *pole) {
  for (int i = 0; i < l; i++)
    tmp[i] = pole[i];
}

double kuro(int *pole, int len);
// ???????????????OK?????£????????°
double shiro(int *pole, int len) {
  if (array[len] != -1) {
    //	printf("%d\\n", array[len]);
    return array[len];
  }
  int tmp[l]; /* pole ???????????? */
  double count = 0;
  //??????????????\\??????
  //????????\\????????????????????§???????????????????????????
  //?????????????????????????????§???????????????????????????????????????
  copy(tmp, pole);
  tmp[len] = SHIRO;
  if (len + 1 <= l) {
    count = kuro(tmp, len + 1);
  }
  array[len] = count;
  return count;
}
// ???????????????OK?????£????????°
double kuro(int *pole, int len) {
  int tmp[l]; /* pole ???????????? */
  double count = 0;
  //??????????????\\??????
  copy(tmp, pole);
  tmp[len] = USUI;
  // check ??????????????????????????????????????°????????????
  if (check(tmp, len + 1)) {
    // print(tmp);
    count += 1 + shiro(tmp, len + 1);
  }
  //??????????????\\??????
  copy(tmp, pole);
  if (len + k <= l) {
    for (int i = 0; i < k; i++)
      tmp[len + i] = ATSUI;
    if (check(tmp, len + k)) {
      // print(tmp);
      count += 1 + shiro(tmp, len + k);
    }
  }
  return count;
}

int main(void) {
  cin >> l >> k;
  int pole[l];
  int len = 0; /* len of disks */
  for (int i = 0; i < l; i++) {
    pole[i] = -1;
  }
  for (int i = 0; i < 200; i++)
    array[i] = -1;
  // cout << kuro(pole, 0) << endl;
  printf("%.0lf\\n", kuro(pole, 0));

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdlib.h>

#define SHIRO 0
#define USUI 1
#define ATSUI 2

using namespace std;

int l, k;
double array[200];
void print(int *pole) {
  for (int i = 0; i < l; i++)
    printf("%d ", pole[i]);
  printf("\\n");
}

bool check(int *pole, int len) {
  // l ?????????????¶????????????????
  if (l < len)
    return false;
  // ???????????\\?????????
  if (pole[0] == SHIRO)
    return false;
  // ???????????\\?????????
  if (pole[len - 1] == SHIRO)
    return false;
  return true;
}

/* copy array */
void copy(int *tmp, int *pole) {
  for (int i = 0; i < l; i++)
    tmp[i] = pole[i];
}

double kuro(int *pole, int len);
// ???????????????OK?????£????????°
double shiro(int *pole, int len) {
  if (array[len] != -1) {
    //	printf("%d\\n", array[len]);
    return array[len];
  }
  int tmp[l]; /* pole ???????????? */
  double count = 0;
  //??????????????\\??????
  //????????\\????????????????????§???????????????????????????
  //?????????????????????????????§???????????????????????????????????????
  copy(tmp, pole);
  tmp[len] = SHIRO;
  if (len + 1 <= l) {
    count = kuro(tmp, len + 1);
  }
  array[len] = count;
  return count;
}
// ???????????????OK?????£????????°
double kuro(int *pole, int len) {
  int tmp[l]; /* pole ???????????? */
  double count = 0;
  //??????????????\\??????
  copy(tmp, pole);
  tmp[len] = USUI;
  // check ??????????????????????????????????????°????????????
  if (check(tmp, len + 1)) {
    // print(tmp);
    count += 1 + shiro(tmp, len + 1);
  }
  //??????????????\\??????
  copy(tmp, pole);
  for (int i = 0; i < k; i++)
    tmp[len + i] = ATSUI;
  if (check(tmp, len + k)) {
    // print(tmp);
    count += 1 + shiro(tmp, len + k);
  }
  return count;
}

int main(void) {
  cin >> l >> k;
  int pole[l];
  int len = 0; /* len of disks */
  for (int i = 0; i < l; i++) {
    pole[i] = -1;
  }
  for (int i = 0; i < 200; i++)
    array[i] = -1;
  // cout << kuro(pole, 0) << endl;
  printf("%.0lf\\n", kuro(pole, 0));

  return 0;
}