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

#include <iostream>
#include <vector>
#define N 1100001
using namespace std;

bool p[N];
vector<int> pr;
int num[N];

int main() {

  for (int i = 0; i < N; i++)
    p[i] = true;
  p[0] = p[1] = false;

  for (int i = 2; i * i < N; i++) {
    if (p[i]) {
      for (int j = 2 * i; j < N; j += i)
        p[j] = false;
    }
  }

  for (int i = 0; i < N; i++)
    if (p[i])
      pr.push_back(i);

  long long A, B;
  cin >> A >> B;

  long long m = max(2LL, A - B);
  for (int i = 0; i < 2 * B + 1; i++)
    num[i] = 100000000;

  for (int i = 0; i < (int)pr.size(); i++) {
    if (A + B < pr[i])
      break;
    long long tmp = (m + pr[i] - 1) / pr[i] * pr[i];
    for (long long j = tmp; j <= A + B; j += pr[i]) {

      if (num[j - (A - B)] < 0)
        continue;
      int n = 0;
      long long hoge = j;
      while (!(hoge % pr[i])) {
        hoge /= pr[i];
        n++;
      }

      if (num[j - (A - B)] >= n)
        num[j - (A - B)] = n;
      else
        num[j - (A - B)] = -1;
    }
  }

  int ans = 0;
  long long C = (A - B < 2LL) ? (2LL + B - A) : 0LL;
  for (int i = C; i < 2 * B + 1; i++)
    if (0 <= num[i])
      ans++;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define N 1100001
using namespace std;

bool p[N];
vector<int> pr;
int num[N];

int main() {

  for (int i = 0; i < N; i++)
    p[i] = true;
  p[0] = p[1] = false;

  for (int i = 2; i * i < N; i++) {
    if (p[i]) {
      for (int j = 2 * i; j < N; j += i)
        p[j] = false;
    }
  }

  for (int i = 0; i < N; i++)
    if (p[i])
      pr.push_back(i);

  long long A, B;
  cin >> A >> B;

  for (int i = 0; i < 2 * B + 1; i++)
    num[i] = 100000000;

  for (int i = 0; i < (int)pr.size(); i++) {
    if (A + B < pr[i])
      break;
    long long tmp = (A - B + pr[i] - 1) / pr[i] * pr[i];
    for (long long j = tmp; j <= A + B; j += pr[i]) {

      if (num[j - (A - B)] < 0)
        continue;
      int n = 0;
      long long hoge = j;
      while (!(hoge % pr[i])) {
        hoge /= pr[i];
        n++;
      }

      if (num[j - (A - B)] >= n)
        num[j - (A - B)] = n;
      else
        num[j - (A - B)] = -1;
    }
  }

  int ans = 0;
  long long C = (A - B < 2LL) ? (2LL + B - A) : 0LL;
  for (int i = C; i < 2 * B + 1; i++)
    if (0 <= num[i])
      ans++;
  cout << ans << endl;
}
Problem p01392 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

int main() {
  bool np[1000000] = {0};
  np[0] = np[1] = 1;
  REP(i, 1000000)
  if (!np[i])
    for (int j = i * 2; j < 1000000; j += i)
      np[j] = 1;
  vector<int> p;
  REP(i, 1000000) if (!np[i]) p.push_back(i);
  typedef long long ll;
  ll aa, bb;
  cin >> aa >> bb;
  ll a = max(2LL, aa - bb);
  ll b = aa + bb;

  int n = b - a + 1;
  int e[n];
  REP(i, n) e[i] = INF;
  REP(i, p.size()) {
    int pp = p[i];

    for (ll j = (a + pp - 1) / pp * pp; j <= b; j += pp) {
      if (e[j - a] == -1)
        continue;

      ll jj = j;
      int cnt = 0;
      while (jj % pp == 0) {
        jj /= pp;
        cnt++;
      }
      // cout << pp <<  " " << j << " " << cnt << endl;
      e[j - a] = (e[j - a] < cnt) ? -1 : cnt;
    }
  }
  cout << n - count(e, e + n, -1) << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

int main() {
  bool np[1000000] = {0};
  np[0] = np[1] = 1;
  REP(i, 1000000)
  if (!np[i])
    for (int j = i * 2; j < 1000000; j += i)
      np[j] = 1;
  vector<int> p;
  REP(i, 1000000) if (!np[i]) p.push_back(i);
  typedef long long ll;
  ll aa, bb;
  cin >> aa >> bb;
  int a = max(2LL, aa - bb);
  int b = aa + bb;

  int n = b - a + 1;
  int e[n];
  REP(i, n) e[i] = INF;
  REP(i, p.size()) {
    int pp = p[i];

    for (ll j = (a + pp - 1) / pp * pp; j <= b; j += pp) {
      cout << j << endl;
      if (e[j - a] == -1)
        continue;

      int jj = j;
      int cnt = 0;
      while (jj % pp == 0) {
        jj /= pp;
        cnt++;
      }
      // cout << pp <<  " " << j << " " << cnt << endl;
      e[j - a] = (e[j - a] < cnt) ? -1 : cnt;
    }
  }
  cout << n - count(e, e + n, -1) << endl;
}
Problem p01392 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void primeNumber(
    int N,
    vector<bool> &
        prime) // 0ツ暗按湘」Nツ暗按可コツづ個青ョツ青板つゥツづァツ素ツ青板づーツ探ツつキ
{
  prime.assign(N + 1, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= N; i++) {
    if (prime[i]) {
      for (int j = i; i * j <= N; j++) {
        prime[i * j] = false;
      }
    }
  }
}

int main() {
  long long a, b;
  cin >> a >> b;
  a = a - b;
  b = a + 2 * b;
  a = max(a, 2LL);

  vector<bool> prime(1000500, true);
  primeNumber(1000500, prime);

  vector<int> prev(b - a + 1, INT_MAX);
  for (long long i = 2; i * i <= b; ++i) {
    if (!prime[i])
      continue;

    for (long long j = (a + i - 1) / i * i; j <= b; j += i) {
      long long x = j;
      int curr = 0;
      while (x % i == 0) {
        x /= i;
        ++curr;
      }
      if (curr > prev[j - a])
        prev[j - a] = -1;
      else
        prev[j - a] = curr;
    }
  }

  int ret = 0;
  for (int i = 0; i < b - a + 1; ++i) {
    if (prev[i] != -1)
      ++ret;
  }
  cout << ret << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void primeNumber(
    int N,
    vector<bool> &
        prime) // 0ツ暗按湘」Nツ暗按可コツづ個青ョツ青板つゥツづァツ素ツ青板づーツ探ツつキ
{
  prime.assign(N + 1, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= N; i++) {
    if (prime[i]) {
      for (int j = i; i * j <= N; j++) {
        prime[i * j] = false;
      }
    }
  }
}

int main() {
  long long a, b;
  cin >> a >> b;
  a = a - b;
  b = a + 2 * b;
  a = max(a, 2LL);

  vector<bool> prime(1000500, true);
  primeNumber(1000500, prime);

  vector<int> prev(b - a + 1, INT_MAX);
  for (long long i = 2; i * i <= b; ++i) {
    if (!prime[i])
      continue;

    for (int j = 0; j < b - a + 1; ++j) {
      if (prev[j] == -1)
        continue;
      int x = a + j;
      if (x % i == 0) {
        int curr = 0;
        while (x % i == 0) {
          x /= i;
          ++curr;
        }
        if (curr > prev[j])
          prev[j] = -1;
        else
          prev[j] = curr;
      }
    }
  }

  int ret = 0;
  for (int i = 0; i < b - a + 1; ++i) {
    if (prev[i] != -1)
      ++ret;
  }
  cout << ret << endl;

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int k(int a) {
  for (int i = 0;; i++) {
    if (a - 26 * i >= 'a' && a - 26 * i <= 'z')
      return a - 26 * i;
  }
}
int main() {
  int a;
  while (cin >> a, a) {
    string b;
    cin >> b;
    int x[100], y[100];
    for (int c = 0; c < a; c++) {
      scanf("%d%d", &x[c], &y[c]);
      x[c]--;
      y[c]--;
    }
    for (int i = a - 1; i >= 0; i--) {
      int d = (int)b[x[i]] + abs(x[i] - y[i]),
          e = (int)b[y[i]] + abs(x[i] - y[i]);
      d = k(d);
      e = k(e);
      b[x[i]] = e;
      b[y[i]] = d;
    }
    cout << b << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int k(int a) {
  for (int i = 0;; i++) {
    if (a - 26 * i >= 'a' && a - 26 * i <= 'z')
      return a - 26 * i;
  }
}
int main() {
  int a;
  while (cin >> a, a) {
    string b;
    cin >> b;
    int x[100], y[100];
    for (int c = 0; c < a; c++) {
      scanf("%d%d", &x[c], &y[c]);
      x[c]--;
      y[c]--;
    }
    for (int i = a - 1; i >= 0; i--) {
      int d = (int)b[x[i]] + abs(x[i] - y[i]),
          e = (int)b[y[i]] + abs(x[i] - y[i]);
      d = k((char)d);
      e = k((char)e);
      b[x[i]] = e;
      b[y[i]] = d;
    }
    cout << b << endl;
  }
}
Problem p01398 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  int a[110];
  int b[110];
  string s;
  while (cin >> n, n) {
    cin >> s;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }

    for (int i = n - 1; i >= 0; i--) {
      int x = b[i] - a[i];
      int p = a[i] - 1, q = b[i] - 1;
      swap(s[p], s[q]);

      s[p] = (s[p] - 'a' + x) % 26 + 'a';
      s[q] = (s[q] - 'a' + x) % 26 + 'a';
    }
    cout << s << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  int a[30];
  int b[30];
  string s;
  while (cin >> n, n) {
    cin >> s;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }

    for (int i = n - 1; i >= 0; i--) {
      int x = b[i] - a[i];
      int p = a[i] - 1, q = b[i] - 1;
      swap(s[p], s[q]);
      s[p] = s[p] + x, s[q] = s[q] + x;

      if (s[p] < 'a' || 'z' < s[p])
        s[p] -= 'z' - 'a' + 1;
      if (s[q] < 'a' || 'z' < s[q])
        s[q] -= 'z' - 'a' + 1;
    }
    cout << s << endl;
  }
}
Problem p01399 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define INF 10000000
int mini(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
int maxim(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
int saidai(int m /**/, int b /*難易度*/) {
  int a = 0;
  while (a <= m) {
    a += b;
  }
  a -= b;
  return a;
}
int saishou(int m, int tan, int i, int a[], int b[]) {
  int d;
  d = a[i];
  while (d <= m) {
    if (b[tan] == d && a[tan] <= a[i])
      return d;
    if (b[tan] < d)
      return d;
    d += a[i];
  }
  return 0;
}

int main() {
  while (1) {
    int n, m, i, j, a[1001] /*難易度*/, b[1001] /*申請*/, tan, c;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (i = 0; i < 1001; i++) {
      a[i] = 0;
      b[i] = 0;
    }
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (i == 0) {
        b[i] = saidai(m, a[i]);
        tan = i;
      } else {
        b[i] = saishou(m, tan, i, a, b);
        if (b[i] == 0) {
          b[i] = saidai(m, a[i]);
          tan = i;
        }
      }
    }
    c = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == a[tan] && b[i] == b[tan])
        c++;
    }
    if (c >= 2) {
      tan = n - 1;
    }
    cout << tan + 1 << endl;
  }
  return 0;
}

Error: 0
sh: 1: pause: not found


Fixed submission:

#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int saidai(int m /**/, int b /*難易度*/) {
  int a = 0;
  while (a <= m) {
    a += b;
  }
  a -= b;
  return a;
}
int saishou(int m, int tan, int i, int a[], int b[]) {
  int d;
  d = a[i];
  while (d <= m) {
    if (b[tan] == d && a[tan] <= a[i])
      return d;
    if (b[tan] < d)
      return d;
    d += a[i];
  }
  return 0;
}

int main() {
  while (1) {
    int n, m, i, j, a[1001] /*難易度*/, b[1001] /*申請*/, tan, c;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (i = 0; i < 1001; i++) {
      a[i] = 0;
      b[i] = 0;
    }
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (i == 0) {
        b[i] = saidai(m, a[i]);
        tan = i;
      } else {
        b[i] = saishou(m, tan, i, a, b);
        if (b[i] == 0) {
          b[i] = saidai(m, a[i]);
          tan = i;
        }
      }
    }
    c = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == a[tan] && b[i] == b[tan])
        c++;
    }
    cout << tan + 1 << endl;
  }
  system("pause");
  return 0;
}
Problem p01399 (C++) — buggy submission, verdict: Runtime Error

// 50
#include <algorithm>
#include <iostream>

using namespace std;

struct S {
  int d, t, n;
  bool operator<(S a) const {
    if (t != a.t) {
      return t < a.t;
    } else {
      return d < a.d;
    }
  }
};

int main() {
  for (int n, m; cin >> n >> m, n | m;) {
    S p[1000];
    for (int i = 0; i < n; i++) {
      cin >> p[i].d;
      p[i].n = i + 1;
      p[i].t = m / p[i].d * p[i].d;
    }
    sort(p, p + n);
    if (!(p[0] < p[1]) && !(p[1] < p[0])) {
      cout << n << endl;
    } else {
      cout << p[0].n << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

// 50
#include <algorithm>
#include <iostream>

using namespace std;

struct S {
  int d, t, n;
  bool operator<(S a) const {
    if (t != a.t) {
      return t < a.t;
    } else {
      return d < a.d;
    }
  }
};

int main() {
  for (int n, m; cin >> n >> m, n | m;) {
    S p[40];
    for (int i = 0; i < n; i++) {
      cin >> p[i].d;
      p[i].n = i + 1;
      p[i].t = m / p[i].d * p[i].d;
    }
    sort(p, p + n);
    if (!(p[0] < p[1]) && !(p[1] < p[0])) {
      cout << n << endl;
    } else {
      cout << p[0].n << endl;
    }
  }
  return 0;
}
Problem p01400 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

const int MAX = 500;
const int INF = 1e9;

int main() {
  int n, m;

  while (cin >> n >> m, n | m) {
    map<string, int> mp;
    int dist[MAX + 1][MAX + 1];
    string a, b, start, goal, via;
    int c, d;

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        dist[i][j] = INF;
      }
    }

    cin >> start >> via >> goal;

    int s = 1;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c >> d;

      if (!mp[a]) {
        mp[a] = s++;
      }
      if (!mp[b]) {
        mp[b] = s++;
      }

      dist[mp[a]][mp[b]] = dist[mp[b]][mp[a]] = c / 40 + d;
    }

    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }

    cout << dist[mp[start]][mp[via]] + dist[mp[via]][mp[goal]] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

const int MAX = 500;
const int INF = 1e9;

int main() {
  int n, m;

  while (cin >> n >> m, n | m) {
    map<string, int> mp;
    int dist[MAX][MAX];
    string a, b, start, goal, via;
    int c, d;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = INF;
      }
    }

    cin >> start >> via >> goal;

    int s = 1;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c >> d;

      if (!mp[a]) {
        mp[a] = s++;
      }
      if (!mp[b]) {
        mp[b] = s++;
      }

      dist[mp[a]][mp[b]] = dist[mp[b]][mp[a]] = c / 40 + d;
    }

    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }

    cout << dist[mp[start]][mp[via]] + dist[mp[via]][mp[goal]] << endl;
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int d1[550], d2[550];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m), n) {
    map<string, int> mp;
    vector<P> E[550];
    string s, p, g;
    cin >> s >> p >> g;
    mp[s] = 0;
    mp[p] = 1;
    mp[g] = 2;
    rep(i, m) {
      string a, b;
      int d, t;
      cin >> a >> b >> d >> t;
      if (mp.find(a) == mp.end())
        mp[a] = mp.size();
      if (mp.find(b) == mp.end())
        mp[b] = mp.size();
      E[mp[a]].push_back(P(d / 40 + t, mp[b]));
      E[mp[b]].push_back(P(d / 40 + t, mp[a]));
    }
    priority_queue<P, vector<P>, greater<P>> que;
    memset(d1, 0x3f, sizeof(d1));
    d1[0] = 0;
    que.push(P(0, 0));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      if (d1[p.second] != p.first)
        continue;
      for (P u : E[p.second]) {
        if (d1[u.second] > p.first + u.first) {
          d1[u.second] = p.first + u.first;
          que.push(P(d1[u.second], u.second));
        }
      }
    }
    memset(d2, 0x3f, sizeof(d2));
    d2[1] = 0;
    que.push(P(0, 1));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      if (d2[p.second] != p.first)
        continue;
      for (P u : E[p.second]) {
        if (d2[u.second] > p.first + u.first) {
          d2[u.second] = p.first + u.first;
          que.push(P(d2[u.second], u.second));
        }
      }
    }
    printf("%d\\n", d1[1] + d2[2]);
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int d1[500], d2[500];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m), n) {
    map<string, int> mp;
    vector<P> E[500];
    string s, p, g;
    cin >> s >> p >> g;
    mp[s] = 0;
    mp[p] = 1;
    mp[g] = 2;
    rep(i, m) {
      string a, b;
      int d, t;
      cin >> a >> b >> d >> t;
      if (mp.find(a) == mp.end())
        mp[a] = mp.size();
      if (mp.find(b) == mp.end())
        mp[b] = mp.size();
      E[mp[a]].push_back(P(d / 40 + t, mp[b]));
      E[mp[b]].push_back(P(d / 40 + t, mp[a]));
    }
    priority_queue<P, vector<P>, greater<P>> que;
    memset(d1, 0x3f, sizeof(d1));
    d1[0] = 0;
    que.push(P(0, 0));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      if (d1[p.second] != p.first)
        continue;
      for (P u : E[p.second]) {
        if (d1[u.second] > p.first + u.first) {
          d1[u.second] = p.first + u.first;
          que.push(P(d1[u.second], u.second));
        }
      }
    }
    memset(d2, 0x3f, sizeof(d2));
    d2[1] = 0;
    que.push(P(0, 1));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      if (d2[p.second] != p.first)
        continue;
      for (P u : E[p.second]) {
        if (d2[u.second] > p.first + u.first) {
          d2[u.second] = p.first + u.first;
          que.push(P(d2[u.second], u.second));
        }
      }
    }
    printf("%d\\n", d1[1] + d2[2]);
  }
}
Problem p01400 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <string>

using namespace std;
const int INF = 999999999;
int dist[500][500];

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    map<string, int> id;
    int k = 0;
    string s, p, g;
    cin >> s >> p >> g;
    if (!id.count(s))
      id[s] = k++;
    if (!id.count(p))
      id[p] = k++;
    if (!id.count(g))
      id[g] = k++;

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        dist[i][j] = INF;
      }
      dist[i][i] = 0;
    }

    for (int i = 0; i < m; ++i) {
      string a, b;
      int d, t;
      cin >> a >> b >> d >> t;
      if (!id.count(a))
        id[a] = k++;
      if (!id.count(b))
        id[b] = k++;
      dist[id[a]][id[b]] = dist[id[b]][id[a]] = d / 40 + t;
    }
    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }
    cout << dist[id[s]][id[p]] + dist[id[p]][id[g]] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
const int INF = 999999999;
int D[501][501];
struct Data {
  string a;
  string b;
  int c;
  int d;
};

void solve() {
  int n, m;
  while (cin >> n >> m, n || m) {
    string s, p, g;
    cin >> s >> p >> g;
    vector<Data> E(m);
    set<string> Set;
    for (int i = 0; i < m; ++i) {
      cin >> E[i].a >> E[i].b >> E[i].c >> E[i].d;
      Set.insert(E[i].a);
      Set.insert(E[i].b);
    }
    map<string, int> Map;
    int count = 0;
    for (set<string>::iterator Ite = Set.begin(); Ite != Set.end(); ++Ite) {
      Map[*Ite] = count;
      count++;
    }
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j) {
        D[i][j] = INF;
      }
    }
    for (int i = 0; i < m; ++i) {
      Data data = E[i];
      D[Map[data.a]][Map[data.b]] = data.c / 40 + data.d;
      D[Map[data.b]][Map[data.a]] = D[Map[data.a]][Map[data.b]];
    }
    for (int i = 0; i < m; ++i) {
      D[i][i] = 0;
    }
    for (int k = 0; k < m; ++k) {
      for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
          D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
        }
      }
    }
    cout << D[Map[s]][Map[p]] + D[Map[p]][Map[g]] << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p01400 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;
long long int edge[800][800];
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    map<string, int> name;
    string S, P, G;
    int all = 1;
    for (int i = 0; i < 800; i++)
      for (int j = 0; j < 800; j++)
        edge[i][j] = 1000000000;
    cin >> S >> P >> G;
    for (int i = 0; i < m; i++) {
      string a_name, b_name;
      int x, y, a, b;
      cin >> a_name >> b_name >> x >> y;
      if (name[a_name] == 0)
        name[a_name] = all++;
      if (name[b_name] == 0)
        name[b_name] = all++;
      a = name[a_name];
      b = name[b_name];
      edge[a][b] = edge[b][a] = x / 40 + y;
    }
    for (int k = 0; k < all; k++) {
      for (int i = 0; i < all; i++) {
        for (int j = 0; j < all; j++) {
          edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
        }
      }
    }
    cout << edge[name[S]][name[P]] + edge[name[P]][name[G]] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#define INF 100000000
using namespace std;
int edge[500][500];
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    map<string, int> name;
    string S, P, G;
    int all = 0;
    for (int i = 0; i < 500; i++)
      for (int j = 0; j < 500; j++)
        edge[i][j] = INF;
    cin >> S >> P >> G;
    for (int i = 0; i < m; i++) {
      string a_name, b_name;
      int x, y, a, b;
      cin >> a_name >> b_name >> x >> y;
      if (name[a_name] == 0)
        name[a_name] = all++;
      if (name[b_name] == 0)
        name[b_name] = all++;
      a = name[a_name];
      b = name[b_name];
      edge[a][b] = edge[b][a] = x / 40 + y;
    }
    for (int k = 0; k < all; k++) {
      for (int i = 0; i < all; i++) {
        for (int j = 0; j < all; j++) {
          edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
        }
      }
    }
    cout << edge[name[S]][name[P]] + edge[name[P]][name[G]] << endl;
  }
  return 0;
}