alexjercan/bugnet huggingface dataset:
Problem p01132 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
int main() {
  int xx = 0;
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    if (xx == 1)
      cout << endl;
    xx = 1;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int memo = a * 10 + b * 50 + c * 100 + d * 500;
    memo -= n;
    d -= memo / 500;
    memo %= 500;
    c -= memo / 100;
    memo %= 100;
    b -= memo / 50;
    memo %= 50;
    a -= memo / 10;
    if (a > 0)
      cout << "10 " << a << endl;
    if (b > 0)
      cout << "50 " << b << endl;
    if (c > 0)
      cout << "100 " << c << endl;
    if (d > 0)
      cout << "500 " << d << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lpin(a, i, n)                                                          \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }
int ans = 100;
int aa, ab, ac, ad;
void calc(int a, int b, int c, int d, int n, int now) {
  if (now >= n) {
    int mem, mem2;
    mem = now - n;
    if (mem / 500 + mem % 500 / 100 + mem % 100 / 50 + mem % 50 / 10 >= 5)
      return;
    if (ans > mem / 500 + mem % 500 / 100 + mem % 100 / 50 + mem % 50 / 10) {
      ans = mem / 500 + mem % 500 / 100 + mem % 100 / 50 + mem % 50 / 10;
      aa = a;
      ab = b;
      ac = c;
      ad = d;
    }
  }
  if (a == 0 && b == 0 && c == 0 && d == 0)
    return;
  if (a > 0)
    calc(a - 1, b, c, d, n, now + 10);
  if (b > 0)
    calc(a, b - 1, c, d, n, now + 50);
  if (c > 0)
    calc(a, b, c - 1, d, n, now + 100);
  if (d > 0)
    calc(a, b, c, d - 1, n, now + 500);
}

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    ans = 100;
    calc(a, b, c, d, n, 0);
    if (a - aa > 0)
      cout << "10 " << a - aa << endl;
    if (b - ab > 0)
      cout << "50 " << b - ab << endl;
    if (c - ac > 0)
      cout << "100 " << c - ac << endl;
    if (d - ad > 0)
      cout << "500 " << d - ad << endl;
  }
  return 0;
}
Problem p01132 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int coin[4] = {10, 50, 100, 500};
const int inf = 1000000;

int main() {
  int n, a[4], b[4], c[4], s, t, u, v;
  bool f = false;

  while (cin >> n && n) {
    if (f) {
      cout << endl;
    }
    v = 0;
    for (int i = 0; i < 4; i++) {
      cin >> a[i];
      b[i] = c[i] = 0;
      v += a[i];
    }
    s = t = inf;

    for (int i = 0; i <= a[3]; i++) {
      for (int j = 0; j <= a[2]; j++) {
        for (int k = 0; k <= a[1]; k++) {
          for (int l = 0; l <= a[0]; l++) {
            s = l * coin[0] + k * coin[1] + j * coin[2] + i * coin[3];
            if (s >= n) {
              s -= n;
              u = v - (l + k + j + i);
              for (int m = 3; m >= 0; m--) {
                c[m] = (s / coin[m]);
                u += c[m];
                s %= coin[m];
              }
              if (u < t) {
                t = u;
                b[0] = l;
                b[1] = k;
                b[2] = j;
                b[3] = i;
              }
            }
          }
        }
      }
    }

    for (int i = 0; i < 4; i++) {
      if (b[i] > 0) {
        cout << coin[i] << " " << b[i] << endl;
      }
    }
    f = true;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main(int argc, char **argv) {
  int c[4], k[4], s, t, r[4], a = 0, b[4] = {10, 50, 100, 500};

  while (1) {
    cin >> t;
    if (t == 0) {
      break;
    } else if (a == 1) {
      cout << endl;
    }
    a = 1;
    for (int i = 0; i < 4; i++) {
      cin >> c[i];
      k[i] = r[i] = 0;
    }
    s = t;
    for (int i = 3; i >= 0; i--) {
      if (s >= b[i]) {
        k[i] += s / b[i];
        s -= k[i] * b[i];
      }
    }

    for (int i = 0, f = 0; i < 4; i++, f = 0) {
      if (k[i] - c[i] <= 0) {
        r[i] = k[i];
        c[i] -= k[i];
      } else {
        s = b[i] * k[i];
        for (int j = i - 1; j >= 0; j++) {
          if (s - c[j] * b[j] <= 0) {
            r[j] += s / b[j];
            c[j] -= r[j];
            f = 1;
            break;
          }
        }
        k[i + 1]++;
      }
    }

    for (int i = 0; i < 4; i++) {
      if (r[i] > 0) {
        cout << b[i] << " " << r[i] << endl;
      }
    }
  }

  return 0;
}
Problem p01132 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int main() {

  int n, c[4];
  int sum;
  int data[] = {10, 50, 100, 500};
  bool f = false;

  while (1) {

    cin >> n;
    if (n == 0)
      break;
    if (f)
      cout << endl;
    f = true;

    sum = 0;
    for (int i = 0; i < 4; i++) {
      cin >> c[i];
      sum += c[i] * data[i];
    }

    sum -= n;

    for (int i = 3; i >= 0; i--) {
      c[i] -= min(c[i], sum / data[i]);
      sum %= data[i];
    }

    for (int i = 0; i < 4; i++) {
      if (c[i] != 0)
        cout << data[i] << " " << c[i] << endl;
    }
  }
}

Error: WA

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

void ans_print(int a[], int b, int c) {
  int dat[501] = {0};
  int data[] = {10, 50, 100, 500};
  for (int i = 0; i < c; i++) {
    if ((b & 1) == 1)
      dat[a[i]]++;
    b >>= 1;
  }
  for (int i = 0; i < 4; i++) {
    if (dat[data[i]] >= 1) {
      cout << data[i] << " " << dat[data[i]] << endl;
    }
  }
}

int mai(int b, int c) {
  int cnt = 0;
  for (int i = 0; i < c; i++) {
    if ((b & 1) == 1)
      cnt++;
    b >>= 1;
  }
  return cnt;
}

int gaku(int a[], int b, int c) {
  int sum = 0;
  for (int i = 0; i < c; i++) {
    if ((b & 1) == 1)
      sum += a[i];
    b >>= 1;
  }
  return sum;
}

int oturi(int n) {
  int data[] = {10, 50, 100, 500};
  int cnt = 0;
  for (int i = 3; i >= 0; i--) {
    cnt += n / data[i];
    n %= data[i];
  }
  return cnt;
}

int main() {

  int n, k[20], ci;
  int data[] = {10, 50, 100, 500};
  int cnt;
  int tnum, mnum, sum;
  int min_turi, min_use, ans;

  while (1) {

    cin >> n;
    if (n == 0)
      break;

    cnt = 0;
    min_turi = 10000000;
    min_use = 10000000;

    for (int i = 0; i < 4; i++) {
      cin >> ci;
      for (int j = 0; j < ci; j++) {
        k[cnt] = data[i];
        cnt++;
      }
    }

    for (long long i = 0; i < (1 << cnt); i++) {
      /*sum=gaku(k,i,cnt);
      if(sum>=n){
              mnum=mai(i,cnt);
              tnum=oturi(sum-n)+cnt;
              if(min_turi>tnum||(min_turi==tnum&&min_use>mnum)){
                      min_turi=tnum;
                      min_use=mnum;
                      ans=i;
              }
      }*/
    }
    ans_print(k, 1, cnt);
  }
}
Problem p01132 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  int n;
  vlai p = {10, 50, 100, 500, 0};
  while (cin >> n, n) {
    vlai c(0, 4);
    cin >> c[0] >> c[1] >> c[2] >> c[3];
    int b = (p * c).sum() - n;
    rrep(i, 4) while (b >= p[i]) {
      b -= p[i];
      c[i]--;
    }
    if (p[4]++)
      cout << endl;
    rep(i, 4) {
      if (c[i] > 0)
        cout << p[i] << " " << c[i] << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for (int i = 0; i < n; i++)
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vlai = valarray<int>;

struct Wal {
  vlai c;
  Wal() { c = vlai(0, 4); }
  Wal(vlai a) { c = a; }
  void print() {
    if (c[0])
      cout << "10 " << c[0] << endl;
    if (c[1])
      cout << "50 " << c[1] << endl;
    if (c[2])
      cout << "100 " << c[2] << endl;
    if (c[3])
      cout << "500 " << c[3] << endl;
  }
};

int main(void) {
  int n, h = 0;
  vector<vlai> oturi(1, {0, 0, 0, 0});
  rep(i, 66 * 20) {
    auto nxt = oturi.back();
    nxt[0]++;
    if (nxt[0] == 5) {
      nxt[0] = 0, nxt[1]++;
      if (nxt[1] == 2) {
        nxt[1] = 0, nxt[2]++;
        if (nxt[2] == 5) {
          nxt[2] = 0, nxt[3]++;
        }
      }
    }
    oturi.push_back(nxt);
  }
  while (cin >> n, n) {
    n /= 10;
    Wal p;
    vlai r = {1, 5, 10, 50};
    cin >> p.c[0] >> p.c[1] >> p.c[2] >> p.c[3];
    vector<Wal> val;
    rep(i, p.c[3] + 1) {
      rep(j, p.c[2] + 1) {
        rep(k, p.c[1] + 1) {
          int total = 50 * i + 10 * j + 5 * k;
          int d = n - total;
          if (d > p.c[0])
            continue;
          for (int l = 0; l < p.c[0] + 1; l++) {
            Wal q({l, k, j, i});
            if (total + l - n >= 0 && (oturi[total + l - n] * q.c).sum() == 0)
              val.push_back(q);
          }
        }
      }
    }
    sort(all(val), [p, r, oturi, n](Wal a, Wal b) {
      return (p.c - a.c + oturi[(a.c * r).sum() - n]).sum() <
             (p.c - b.c + oturi[(b.c * r).sum() - n]).sum();
    });
    if (h++)
      cout << endl;
    val.front().print();
  }
}
Problem p01132 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

vector<map<int, int>> ans;

int mon[] = {10, 50, 100, 500};
int ccount(map<int, int> co, int f);

int main() {
  while (1) {
    int fee;
    cin >> fee;
    if (fee == 0)
      break;

    map<int, int> coin, ucoin, acoin;

    int count = 0;
    for (int i = 0; i < 4; i++) {
      int n;
      cin >> n;
      count += n;
      coin[mon[i]] = n;
      ucoin[mon[i]] = 0;
    }
    int tans = 1e9;
    for (int i = 0; i <= coin[mon[0]]; i++) {
      ucoin[mon[0]] = i;
      for (int j = 0; j <= coin[mon[1]]; j++) {
        ucoin[mon[1]] = j;
        for (int k = 0; k <= coin[mon[2]]; k++) {
          ucoin[mon[2]] = k;
          for (int l = 0; l <= coin[mon[3]]; l++) {
            ucoin[mon[3]] = l;
            int ucount = i + j + k + l;
            int lcount = count - ucount + ccount(ucoin, fee);
            if (tans > lcount) {
              tans = lcount;
              acoin = ucoin;
            }
          }
        }
      }
    }

    ans.push_back(acoin);
  }

  for (int i = 0; i < ans.size(); i++) {
    if (i != 0)
      cout << endl;
    for (int j = 0; j < 4; j++) {
      if (ans[i][mon[j]] != 0)
        cout << mon[j] << " " << ans[i][mon[j]] << endl;
    }
  }
}

int ccount(map<int, int> co, int f) {
  int am = 0;
  for (int i = 0; i < 4; i++) {
    am += co[mon[i]] * mon[i];
  }

  int cm = 0;
  if (am >= f) {
    cm = am - f;
  } else {
    return 1e9;
  }

  int cnt = 0;
  for (int i = 3; i >= 0; i--) {
    int tn = cm / mon[i];
    cnt += tn;
    cm -= tn * mon[i];
  }

  return cnt;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

vector<map<int, int>> ans;

int mon[] = {10, 50, 100, 500};
int ccount(map<int, int> co, int f);

int main() {
  while (1) {
    int fee;
    cin >> fee;
    if (fee == 0)
      break;

    map<int, int> coin, ucoin;

    for (int i = 0; i < 4; i++) {
      int n;
      cin >> n;
      coin[mon[i]] = n;
      ucoin[mon[i]] = 0;
    }

    map<int, int> dp[4][20];
    dp[0][0] = ucoin;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < coin[mon[i]]; j++) {
        ucoin = dp[i][j];
        ucoin[mon[i]]++;
        if (ccount(dp[i][j], fee) >= ccount(ucoin, fee)) {
          dp[i][j + 1] = ucoin;
        } else {
          dp[i][j + 1] = dp[i][j];
        }
      }
      dp[i + 1][0] = dp[i][coin[mon[i]]];
    }

    ans.push_back(dp[3][coin[mon[3]]]);
  }

  for (int i = 0; i < ans.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (ans[i][mon[j]] != 0)
        cout << mon[j] << " " << ans[i][mon[j]] << endl;
    }
    cout << endl;
  }
}

int ccount(map<int, int> co, int f) {
  int am = 0;
  for (int i = 0; i < 4; i++) {
    am += co[mon[i]] * mon[i];
  }

  int cm = 0;
  if (am > f) {
    cm = am - f;
  } else {
    cm = f - am;
  }

  int cnt = 0;
  for (int i = 3; i >= 0; i--) {
    int tn = cm / mon[i];
    cnt += tn;
    cm -= tn * mon[i];
  }

  return cnt;
}
Problem p01133 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int n;
int cx[22];
int cy[22];
bool f[22];
double l[22][22];
int s = 0;
double d;

int kansu(int x, int y) {
  s++;
  if (s == n + 1)
    return 1;
  d += l[x][y];
  f[y] = true;
  bool flag = true;
  for (int i = 2; i < n + 2; i++) {
    if (f[i])
      continue;
    if (d + l[y][i] >= l[1][i]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    for (int i = 2; i < n + 2; i++) {
      if (f[i])
        continue;
      if (kansu(y, i))
        return 1;
    }
  }
  s--;
  d -= l[x][y];
  f[y] = false;
  return 0;
}

int main() {
  while (true) {
    cin >> n >> cx[0] >> cy[0] >> cx[1] >> cy[1];
    if (n == 0)
      break;
    for (int i = 2; i < n + 2; i++) {
      cin >> cx[i] >> cy[i];
      f[i] = false;
    }
    for (int i = 0; i < n + 1; i++) {
      for (int j = i + 1; j < n + 2; j++) {
        int x = cx[i] - cx[j];
        int y = cy[i] - cy[j];
        double z = x * x + y * y;
        l[i][j] = sqrt(z);
        l[j][i] = l[i][j];
      }
    }
    s = 0;
    d = 0.00;
    l[0][0] = 0.00;
    if (kansu(0, 0)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int n;
int cx[22];
int cy[22];
bool f[22];
double l[22][22];
int s = 0;
double d;

int kansu(int x, int y) {
  s++;
  if (s == n + 1)
    return 1;
  d += l[x][y];
  f[y] = true;
  f[1] = true;
  for (int i = 2; i < n + 2; i++) {
    if (d + l[y][i] >= l[1][i]) {
      f[1] = false;
      break;
    }
  }
  if (f[1]) {
    for (int i = 2; i < n + 2; i++) {
      if (f[i])
        continue;
      if (kansu(y, i))
        return 1;
    }
  }
  s--;
  d -= l[x][y];
  f[y] = false;
  return 0;
}

int main() {
  while (true) {
    cin >> n >> cx[0] >> cy[0] >> cx[1] >> cy[1];
    if (n == 0)
      break;
    for (int i = 2; i < n + 2; i++) {
      cin >> cx[i] >> cy[i];
      f[i] = false;
    }
    for (int i = 0; i < n + 1; i++) {
      for (int j = i + 1; j < n + 2; j++) {
        int x = cx[i] - cx[j];
        int y = cy[i] - cy[j];
        double z = x * x + y * y;
        l[i][j] = sqrt(z);
        l[j][i] = l[i][j];
      }
    }
    s = 0;
    d = 0.00;
    l[0][0] = 0.00;
    f[0] = false;
    for (int i = 2; i < n + 2; i++) {
      if (kansu(0, 0)) {
        f[0] = true;
        break;
      }
    }
    if (f[0]) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p01133 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <map>
// S
using namespace std;
typedef pair<int, int> P;
int cx[30], cy[30], n, hx, hy, dx, dy;
map<P, double> mp;
bool func(int S, int now, double time) {
  if (S == (1 << n) - 1)
    return 1;
  for (int i = 0; i < n; i++) {
    if (!(S & (1 << i))) {
      if (mp[P(now, i)] + time >= mp[P(i, n + 1)])
        return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!(S & (1 << i))) {
      double pre = mp[P(now, i)];
      double dis = mp[P(i, n + 1)];
      if (pre + time < dis && func(S | (1 << i), i, time + pre))
        return 1;
    }
  }
  return 0;
}
int main() {
  while (cin >> n >> hx >> hy >> dx >> dy, n || hx || hy || dx || dy) {
    for (int i = 0; i < n; i++)
      cin >> cx[i] >> cy[i];
    cx[n] = hx;
    cy[n] = hy;
    cx[n + 1] = dx;
    cy[n + 1] = dy;
    for (int i = 0; i <= n + 1; i++)
      for (int j = 0; j <= n + 1; j++)
        mp[P(i, j)] = sqrt((cx[i] - cx[j]) * (cx[i] - cx[j]) +
                           (cy[i] - cy[j]) * (cy[i] - cy[j]));
    if (func(0, n, 0.0))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    mp.clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
// S
using namespace std;
typedef pair<int, int> P;
int cx[30], cy[30], n, hx, hy, dx, dy;
map<P, double> mp;
bool func(int S, int now, double time) {
  if (S == (1 << n) - 1)
    return 1;
  for (int i = 0; i < n; i++) {
    if (!(S & (1 << i))) {
      double pre = mp[P(now, i)];
      double dis = mp[P(i, n + 1)];
      if (pre + time < dis && func(S | (1 << i), i, time + pre))
        return 1;
    }
  }
  return 0;
}
int main() {
  while (cin >> n >> hx >> hy >> dx >> dy, n || hx || hy || dx || dy) {
    for (int i = 0; i < n; i++)
      cin >> cx[i] >> cy[i];
    cx[n] = hx;
    cy[n] = hy;
    cx[n + 1] = dx;
    cy[n + 1] = dy;
    for (int i = 0; i <= n + 1; i++)
      for (int j = 0; j <= n + 1; j++)
        mp[P(i, j)] = sqrt((cx[i] - cx[j]) * (cx[i] - cx[j]) +
                           (cy[i] - cy[j]) * (cy[i] - cy[j]));
    if (func(0, n, 0.0))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    mp.clear();
  }
  return 0;
}
Problem p01133 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

#define EPS 1e-10

struct Point {
  double x, y, d;
};
int n;
Point hero, demon;
vector<Point> crystal;
bool ok;

double dist(Point a, Point b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void solve(int now, double time, vector<bool> visited) {
  int i;
  bool f = true;
  if (time - crystal[now].d > -EPS)
    return;
  for (i = 0; i < n; i++) {
    if (visited[i])
      continue;
    if (time + dist(crystal[now], crystal[i]) - crystal[i].d > EPS)
      return;
  }
  for (i = 0; i < n; i++) {
    if (visited[i])
      continue;
    visited[i] = true;
    solve(i, time + dist(crystal[now], crystal[i]), visited);
    visited[i] = false;
    f = false;
  }
  if (f)
    ok = true;
  return;
}

int main() {
  vector<bool> visited;
  int i;
  double hx, hy, dx, dy, x, y;
  double time;
  while (cin >> n >> hx >> hy >> dx >> dy, hx || hy || dx || dy) {
    hero.x = hx;
    hero.y = hy;
    demon.x = dx;
    demon.y = dy;
    crystal.clear();
    visited.resize(n);
    fill(visited.begin(), visited.end(), false);
    for (i = 0; i < n; i++) {
      cin >> x >> y;
      Point p = {x, y, 0};
      p.d = dist(p, demon);
      crystal.push_back(p);
    }
    ok = false;
    for (i = 0; i < n; i++) {
      time = dist(hero, crystal[i]);
      visited[i] = true;
      solve(i, time, visited);
      visited[i] = false;
      if (ok)
        break;
    }
    puts(ok ? "YES" : "NO");
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

#define EPS 1e-10

struct Point {
  double x, y, d;
};
int n;
Point hero, demon;
vector<Point> crystal;
bool ok;

double dist(Point a, Point b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void solve(int now, double time, vector<bool> visited) {
  int i;
  bool f = true;
  if (time - crystal[now].d > -EPS)
    return;
  for (i = 0; i < n; i++) {
    if (visited[i])
      continue;
    visited[i] = true;
    solve(i, time + dist(crystal[now], crystal[i]), visited);
    visited[i] = false;
    f = false;
  }
  if (f)
    ok = true;
  return;
}

int main() {
  vector<bool> visited;
  int i;
  double hx, hy, dx, dy, x, y;
  double time;
  while (cin >> n >> hx >> hy >> dx >> dy, hx || hy || dx || dy) {
    hero.x = hx;
    hero.y = hy;
    demon.x = dx;
    demon.y = dy;
    crystal.clear();
    visited.resize(n);
    fill(visited.begin(), visited.end(), false);
    for (i = 0; i < n; i++) {
      cin >> x >> y;
      Point p = {x, y, 0};
      p.d = dist(p, demon);
      crystal.push_back(p);
    }
    ok = false;
    for (i = 0; i < n; i++) {
      time = dist(hero, crystal[i]);
      visited[i] = true;
      solve(i, time, visited);
      visited[i] = false;
      if (ok)
        break;
    }
    puts(ok ? "YES" : "NO");
  }
}
Problem p01133 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<double, int> P;

int xs[21];
int ys[21];
double h[21];
int n;
double Hypot(int x, int y) { return sqrt(x * x + y * y); }
bool ok(int x, int y, int done, double t) {
  if (done + 1 == (1 << n)) {
    return true;
  }

  vector<P> q;
  for (int i = 0; i < n; i++) {
    if (done & (1 << i))
      continue;
    double d = t + Hypot(xs[i] - x, ys[i] - y);
    if (d >= h[i]) {
      return false;
    }
    q.push_back(P(d, i));
  }
  sort(q.begin(), q.end());
  for (auto p : q) {
    int i = p.second;
    if (ok(xs[i], ys[i], done | (1 << i), p.first)) {
      return true;
    }
  }
  return false;
}
void exec() {
  int hx, hy, dx, dy;
  cin >> n >> hx >> hy >> dx >> dy;
  if ((n | hx | hy | dx | dy) == 0) {
    exit(0);
  }
  for (int i = 0; i < n; i++) {
    cin >> xs[i] >> ys[i];
    h[i] = Hypot(xs[i] - dx, ys[i] - dy);
  }
  if (ok(hx, hy, 0, 0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
int main() {
  while (1)
    exec();
}

Error: 1

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<double, int> P;

int xs[21];
int ys[21];
double h[21];
int n;
double Hypot(int x, int y) { return sqrt(x * x + y * y); }
bool ok(int x, int y, int done, double t) {
  if (done + 1 == (1 << n)) {
    return true;
  }

  vector<P> q;
  for (int i = 0; i < n; i++) {
    if (done & (1 << i))
      continue;
    double d = t + Hypot(xs[i] - x, ys[i] - y);
    if (d >= h[i]) {
      return false;
    }
    q.push_back(P(d, i));
  }
  sort(q.begin(), q.end());
  for (auto p : q) {
    int i = p.second;
    if (ok(xs[i], ys[i], done | (1 << i), p.first)) {
      return true;
    }
  }
  return false;
}
void exec() {
  int hx, hy, dx, dy;
  cin >> n >> hx >> hy >> dx >> dy;
  if ((n | hx | hy | dx | dy) == 0) {
    exit(1);
  }
  for (int i = 0; i < n; i++) {
    cin >> xs[i] >> ys[i];
    h[i] = Hypot(xs[i] - dx, ys[i] - dy);
  }
  if (ok(hx, hy, 0, 0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
int main() {
  while (1)
    exec();
}