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

#include <bits/stdc++.h>
using namespace std;

double dp[10000][20][20];

int main(int argc, char const *argv[]) {
  int n;
  double r, t;
  cin >> n >> r >> t;
  t = t * M_PI / 180.0;
  int x[n], y[n];
  for (int i = 0; i < n; ++i)
    cin >> x[i] >> y[i];

  bool moveok[n][n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        if (i == j || j == k || k == i)
          moveok[i][j][k] = 0;
        else {
          double rad1 = (double)(y[i] - y[j]) / (x[i] - x[j]),
                 rad2 = (double)(y[j] - y[k]) / (x[j] - x[k]);
          if (x[i] == x[j])
            rad1 = (y[i] > y[j]) ? -M_PI / 2 : M_PI / 2;
          else if (x[i] - x[j] > 0)
            rad1 = atan(rad1) + M_PI;
          else
            rad1 = atan(rad1);
          if (x[j] == x[k])
            rad2 = (y[j] > y[k]) ? -M_PI / 2 : M_PI / 2;
          else if (x[j] - x[k] > 0)
            rad2 = atan(rad2) + M_PI;
          else
            rad2 = atan(rad2);
          double rad = fabs(rad1 - rad2);
          while (rad > M_PI)
            rad -= 2 * M_PI;
          if (fabs(rad) < t + 0.0001)
            moveok[i][j][k] = 1;
          else
            moveok[i][j][k] = 0;
        }
      }
    }
  }

  double distance[n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      distance[i][j] =
          sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
    }
  }

  for (int i = 0; i < 10000; ++i) {
    for (int j = 0; j < 20; ++j) {
      for (int k = 0; k < 20; ++k) {
        dp[i][j][k] = 1e6;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (distance[0][i] <= r + 0.0001)
      dp[1][0][i] = distance[0][i], ans = 1;
  }

  for (int i = 1; i < 10000; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        if (dp[i][j][k] != 1e6) {
          ans = max(ans, i);
          for (int l = 0; l < n; ++l) {
            if (moveok[j][k][l]) {
              dp[i + 1][k][l] =
                  min(dp[i + 1][k][l], dp[i][j][k] + distance[k][l]);
              if (dp[i + 1][k][l] > r + 0.0001)
                dp[i + 1][k][l] = 1e6;
              // if(dp[i+1][k][l]>0) ans=max(ans,i+1);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

double dp[1000][20][20];

int main(int argc, char const *argv[]) {
  int n;
  double r, t;
  cin >> n >> r >> t;
  t = t * M_PI / 180.0;
  int x[n], y[n];
  for (int i = 0; i < n; ++i)
    cin >> x[i] >> y[i];

  bool moveok[n][n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        if (i == j || j == k || k == i)
          moveok[i][j][k] = 0;
        else {
          double rad1 = (double)(y[i] - y[j]) / (x[i] - x[j]),
                 rad2 = (double)(y[j] - y[k]) / (x[j] - x[k]);
          if (x[i] == x[j])
            rad1 = (y[i] > y[j]) ? -M_PI / 2 : M_PI / 2;
          else if (x[i] - x[j] > 0)
            rad1 = atan(rad1) + M_PI;
          else
            rad1 = atan(rad1);
          if (x[j] == x[k])
            rad2 = (y[j] > y[k]) ? -M_PI / 2 : M_PI / 2;
          else if (x[j] - x[k] > 0)
            rad2 = atan(rad2) + M_PI;
          else
            rad2 = atan(rad2);
          double rad = fabs(rad1 - rad2);
          while (rad > M_PI)
            rad -= 2 * M_PI;
          if (fabs(rad) < t + 0.0001)
            moveok[i][j][k] = 1;
          else
            moveok[i][j][k] = 0;
        }
      }
    }
  }

  double distance[n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      distance[i][j] =
          sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
    }
  }

  for (int i = 0; i < 1000; ++i) {
    for (int j = 0; j < 20; ++j) {
      for (int k = 0; k < 20; ++k) {
        dp[i][j][k] = 1e6;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (distance[0][i] <= r + 0.0001)
      dp[1][0][i] = distance[0][i], ans = 1;
  }

  for (int i = 1; i < 1000; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        if (dp[i][j][k] != 1e6) {
          ans = max(ans, i);
          for (int l = 0; l < n; ++l) {
            if (moveok[j][k][l]) {
              dp[i + 1][k][l] =
                  min(dp[i + 1][k][l], dp[i][j][k] + distance[k][l]);
              if (dp[i + 1][k][l] > r + 0.0001)
                dp[i + 1][k][l] = 1e6;
              // if(dp[i+1][k][l]>0) ans=max(ans,i+1);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}