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

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

constexpr int64_t mod = 2019;

int main() {
  string s;
  cin >> s;

  int64_t len = s.length();

  vector<int64_t> t(len, 0);
  int64_t num = 0;
  int64_t digit = 1;
  for (int i = len - 1; i >= 0; i--) {
    int d = s[i] - '0';
    d *= digit;
    d %= mod;
    num += d;
    num %= mod;
    t[len - i - 1] = num;
    digit *= 10;
    digit %= mod;
  }

  vector<int64_t> mod_num(mod, 0);
  for (int i = 0; i < len; i++)
    mod_num[t[i]]++;

  int64_t ans = mod_num[0];
  for (int i = 0; i < mod; i++) {
    if (mod_num[i] > 1)
      ans += mod_num[i] * (mod_num[i] - 1) / 2;
  }

  // for(int i = 0; i < mod; i++) {
  //     if(mod_num[i] > 0) cout << i << ": " << mod_num[i] << endl;
  // }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

constexpr int64_t mod = 2019;

int main() {
  string s;
  cin >> s;

  int64_t ans = 0;
  for (int i = s.length() - 1; i >= 3; i--) {
    int64_t num = s[i] - '0';
    int64_t digit = 10;
    for (int j = i - 1; j >= 0; j--) {
      int64_t d = (s[j] - '0') * digit % mod;
      digit *= 10;
      digit %= mod;
      num += d;
      num %= mod;
      if (num == 0) {
        ans++;
        // break;
      }
    }
  }

  cout << ans << endl;

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

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

int main() {
  string s;
  cin >> s;

  int cur = 0;
  int mul = 1;
  vector<int> cnt(2019);
  cnt[0] = 1;

  for (int i = s.size() - 1; i >= 0; --i) {
    cur += mul * (s[i] - '0');
    cur %= 2019;
    ++cnt[cur];
    mul = mul * 10 % 2019;
  }

  long long ans = 0;
  for (int c : cnt) {
    ans += (long long)(c - 1) * c / 2;
  }

  cout << ans << '\\n';
}


Error: TLE

Fixed submission:

#include <iostream>
#include <map>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int dp[n];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (i == j) {
        dp[j] = s[j] - '0';
      } else {
        dp[j] = (dp[j - 1] * 10 + s[j] - '0') % 2019;
        if (dp[j] == 0) {
          ans += 1;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string S;
  long long count = 0;
  cin >> S;
  map<long long, long long> saves;
  saves[0]++;
  long long tens = 1;
  long long a = 0;
  reverse(S.begin(), S.end());
  for (long long i = 0; i < S.size(); i++) {
    a = (a + (S[i] - '0') * tens) % 2019;
    tens = (tens * 10) % 2019;
    // cout<<i<<" "<<a<<endl;
    saves[a]++;
  }

  for (auto k = saves.begin(); k != saves.end(); k++) {
    // cout<<k->first<<" "<<k->second<<endl;
    int amari = k->second;
    count = count + (amari * (amari - 1)) / 2;
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

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

int main() {
  string S;
  long long count = 0;
  cin >> S;
  map<long long, long long> saves;
  saves[0]++;
  for (long long i = 1; i < (long long)S.size() + 1; i++) {
    string a = S.substr(S.size() - i, i);
    long long b = stoll(a);
    // cout<<b<<endl;
    saves[b % 2019]++;
  }

  for (auto k = saves.begin(); k != saves.end(); k++) {
    int amari = k->second;
    count = count + amari * (amari - 1) / 2;
  }
  cout << count << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> mod(2019);
  mod.at(0) = 1;
  int before = 0, temp = 0, dig = 1;
  for (int i = 0; i < n; i++) {
    temp = 0;
    temp = (int)(unsigned char)(s.at(n - i - 1) - '0');

    if (i != 0)
      dig = dig * 10 % 2019;
    temp *= dig;
    temp += before;
    temp %= 2019;
    mod.at(temp)++;
    before = temp;
  }
  int result = 0;
  rep(i, 2019) { result += (mod.at(i) * (mod.at(i) - 1)) / 2; }
  cout << result << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> mod(2019);
  mod.at(0) = 1;
  int before = 0, temp = 0;
  for (int i = 0; i < n; i++) {
    temp = 0;
    temp = (int)(unsigned char)(s.at(n - i - 1) - '0');
    rep(j, i) {
      temp *= 10;
      temp %= 2019;
    }
    temp += before;
    temp %= 2019;
    mod.at(temp)++;
    before = temp;
  }
  int result = 0;
  rep(i, 2019) { result += (mod.at(i) * (mod.at(i) - 1)) / 2; }
  cout << result << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef long long int llint;

string S;

llint sum[2019];

llint mod_pow(llint x, llint n) {
  llint res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x;
    }
    x = x * x;
    n >>= 1;
  }
  return res;
}

llint func(llint n) {
  // if (n <= 1) { return 0; }
  llint res = 1;
  // while (n > 0) {
  //	res *= n;
  //	n--;
  // }
  return n * (n - 1) / 2;
}

int main() {
  cin >> S;
  // cout << 10095 % 2019 << endl;
  int N = (int)S.size();
  vector<llint> a(N);

  a[N - 1] = S[N - 1] - '0';
  sum[a[N - 1]]++;
  // cout << a[N - 1] << endl;
  llint ans = 0;
  llint now = 10;
  for (int i = 1; i < N; i++) {
    llint v = now;
    a[N - 1 - i] = ((S[N - 1 - i] - '0') * v + a[N - i]) % 2019;
    now = (now * 10) % 2019;
    sum[a[N - 1 - i]]++;
    // cout << a[N - 1 - i] << endl;
  }

  for (int i = 0; i < 2019; i++) {
    // if(sum[i] != 0)
    // cout << "sum[" << i << "=" << sum[i] << endl;
    ans += func(sum[i]);
  }

  cout << ans + sum[0] << endl;
}

Error: 0

Fixed submission:

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

using namespace std;

typedef long long int llint;

string S;

int sum[2019];

llint func(llint n) {
  if (n <= 1) {
    return 0;
  }
  llint res = 1;
  while (n > 0) {
    res *= n;
    n--;
  }
  return res / 2;
}

int main() {
  cin >> S;
  // cout << 10095 % 2019 << endl;
  int N = (int)S.size();
  vector<llint> a(N);

  a[N - 1] = S[N - 1] - '0';
  sum[N - 1]++;
  // cout << a[N - 1] << endl;
  llint ans = 0;
  llint now = 10;
  for (int i = 1; i < N; i++) {
    llint v = now;
    a[N - 1 - i] = ((S[N - 1 - i] - '0') * v + a[N - i]) % 2019;
    now = (now * 10) % 2019;
    sum[a[N - 1 - i]]++;
    // cout << a[N - 1 - i] << endl;
  }

  for (int i = 0; i < 2019; i++) {
    // if(sum[i] != 0)
    // cout << "sum[" << i << "=" << sum[i] << endl;
    ans += func(sum[i]);
  }
  cout << ans + sum[0] << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> mod(2019, 0);
  int d = 1;
  int m = 0;
  for (int i = 0; i < N; i++) {
    m += (S.at(N - 1 - i) - '0') * d;
    m %= 2019;
    // cout << m << endl;
    d *= 10;
    d %= 2019;
    mod.at(m)++;
  }
  mod.at(0)++;
  long long count = 0;
  for (int i = 0; i < 2019; i++) {
    count += (mod.at(i) * (mod.at(i) - 1) / 2);
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<long long> mod(2019, 0);
  for (int i = 0; i < N; i++) {
    long long m = stoll(S.substr(i)) % 2019;
    mod.at(m)++;
  }
  mod.at(0)++;
  long long count = 0;
  for (int i = 0; i < 2019; i++) {
    // cout << mod.at(i) << endl;
    count += (mod.at(i) * (mod.at(i) - 1) / 2);
  }
  cout << count << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string S;
  cin >> S;

  int i, j;

  int k = S.size();

  vector<int> T(k + 1);
  vector<int> U(k);

  T.at(0) = S[k - 1] - '0';
  U.at(0) = 1;

  for (int i = 1; i < k; ++i) {
    U.at(i) = (U.at(i - 1) * 10) % 2019;

    T.at(i) = ((((S[k - 1 - i] - '0') * U.at(i)) % 2019) + T.at(i - 1)) % 2019;
  }

  T.at(k) = 0;

  int m = 0;

  vector<long long> a(2019);

  for (i = 0; i < k + 1; ++i) {
    ++a.at(T.at(i));
  }

  long long s = 0;

  for (i = 0; i < 2019; ++i) {
    s += a.at(i) * (a.at(i) - 1) / 2;
  }

  cout << s << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  string S;
  cin >> S;

  int i, j;

  int k = S.size();

  vector<int> T(k + 1);
  vector<int> U(k);

  T.at(0) = S[k - 1] - '0';
  U.at(0) = 1;

  for (int i = 1; i < k; ++i) {
    U.at(i) = (U.at(i - 1) * 10) % 2019;

    T.at(i) = ((((S[k - 1 - i] - '0') * U.at(i)) % 2019) + T.at(i - 1)) % 2019;
  }

  T.at(k) = 0;

  int m = 0;

  for (i = 0; i < k; ++i) {
    for (j = i + 1; j < k + 1; ++j) {
      if (T.at(i) == T.at(j)) {
        ++m;
      }
    }
  }

  cout << m << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 2019;

struct mint {
  ll x; //
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
};

long long ama(int num, int keta) {
  // 10のketa乗を2019で割ったあまりかけるnum
  mint n = 10;
  mint m = n.pow(keta) * num;
  return m.x;
}

int main() {
  string s;
  cin >> s;
  long long ans = 0;
  map<int, int> mp;

  int amari[200005]; // i桁目までの余り
  amari[0] = 0;
  mp[0]++;
  for (int i = 1; i <= s.size(); i++) {
    int tmp = s[s.size() - i] - '0';
    amari[i] = (amari[i - 1] + ama(tmp, i)) % 2019;
    mp[amari[i]]++;
  }
  // for(int i=0;i<=s.size();i++)cout << "[" << amari[i] << "]";

  for (int i = 0; i < 2019; i++) {
    // if(mp[i]>0){
    //   cout << "[" << mp[i] << "]";
    // }
    ans += mp[i] * (mp[i] - 1) / 2;
  }

  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 2019;

struct mint {
  ll x; //
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
};

long long ama(int num, int keta) {
  // 10のketa乗を2019で割ったあまりかけるnum
  mint n = 10;
  mint m = n.pow(keta) * num;
  return m.x;
}

int main() {
  string s;
  cin >> s;
  long long ans = 0;

  int amari[200005]; // i桁目までの余り
  amari[0] = 0;
  for (int i = 1; i <= s.size(); i++) {
    int tmp = s[s.size() - i] - '0';
    amari[i] = (amari[i - 1] + ama(tmp, i)) % 2019;
  }
  // for(int i=0;i<=s.size();i++)cout << "[" << amari[i] << "]";

  for (int i = 0; i <= s.size(); i++) {
    for (int j = i + 1; j <= s.size(); j++) {
      if (amari[i] == amari[j])
        ans++;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs =
    vector<string>; // 左から k + 1 文字目以降の数字列を整数とみなした時の値an +
                    // 10an−1 + ... + 10n−k−1ak+1 を Tk
using vc = vector<char>; // Ti−1 == Tj (mod2019)の時に満たす
using vb = vector<bool>;
const int INFTY = 2147483647;
int main() {
  string s;
  int ans = 0, m[200005], a[2020] = {};
  cin >> s;
  int n = s.length(), k = 1;
  m[n] = 0;
  a[0]++;
  for (int i = n - 1; i >= 0; i--) {
    m[i] = (m[i + 1] + (s[i] - '0') * k) % 2019;
    k = (k * 10) % 2019;
    a[m[i]]++;
  }
  REP(i, 2020) {
    if (a[i] >= 2)
      ans += (a[i] * (a[i] - 1)) / 2;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs =
    vector<string>; // 左から k + 1 文字目以降の数字列を整数とみなした時の値an +
                    // 10an−1 + ... + 10n−k−1ak+1 を Tk
using vc = vector<char>; // Ti−1 == Tj (mod2019)の時に満たす
using vb = vector<bool>;
const int INFTY = 2147483647;
int main() {
  string s;
  int ans = 0, m[200005];
  cin >> s;
  int n = s.length(), k = 1;
  m[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    m[i] = (m[i + 1] + (s[i] - '0') * k) % 2019;
    k = (k * 10) % 2019;
  }
  REP(i, s.length() + 1) {
    FOR(j, i + 1, s.length() + 1) if (m[i] == m[j]) ans++;
  }
  cout << ans << endl;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;

  int n = s.size();
  long long ans = 0;
  long long time = 1;
  long long sum = 0;
  int a[2020];
  memset(a, 0, sizeof(a));

  for (int i = n - 1; i >= 0; i--) {
    sum = sum + (s[i] - '0') * time;
    sum = sum % 2019;
    time = time * 10;
    time = time % 2019;
    a[sum] += 1;
  }

  ans += a[0];

  for (int i = 0; i < 2019; i++) {
    ans += (a[i] * (a[i] - 1)) / 2;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;

  int n = s.size();
  long long ans = 0;
  int a[n];

  long long time = 10;

  a[n - 1] = s[n - 1] - '0';

  for (int i = n - 2; i >= 0; i--) {
    a[i] = (((s[i] - '0') * time) % 2019 + a[i + 1]) % 2019;
    time *= 10;
    time %= 2019;
    if (a[i] == 0) {
      ans++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] == a[j]) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02702 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int moder = 2019;
map<int, int> m;
map<int, int>::iterator it;
long long tenth[200005];

int main() {
  tenth[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    tenth[i] = tenth[i - 1] * 10;
    tenth[i] %= moder;
  }
  string s;
  cin >> s;
  vector<int> arr((int)s.length());
  for (int i = 0; s[i]; i++)
    arr[i] = (int)(s[i] - '0');
  m.insert(make_pair(0, 1));
  long long curr = 0;
  int ret = 0;
  for (int i = 0; i < arr.size(); i++) {
    curr *= 10;
    curr += arr[i];
    curr %= moder;
    long long temp = curr * tenth[s.length() - 1 - i];
    temp %= moder;
    it = m.find((int)temp);
    if (it != m.end()) {
      ret += it->second;
      it->second += 1;
    } else
      m.insert(make_pair((int)temp, 1));
  }
  cout << ret;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int moder = 2019;
map<int, int> m;
map<int, int>::iterator it;
long long tenth(int n) {
  long long ret = 1;
  while (n--) {
    ret *= 10;
    ret %= moder;
  }
  return ret;
}
int main() {
  string s;
  cin >> s;
  vector<int> arr((int)s.length());
  for (int i = 0; s[i]; i++)
    arr[i] = (int)(s[i] - '0');
  m.insert(make_pair(0, 1));
  long long curr = 0;
  int ret = 0;
  for (int i = 0; i < arr.size(); i++) {
    curr *= 10;
    curr += arr[i];
    curr %= moder;
    long long temp = curr * tenth(s.length() - 1 - i);
    temp %= moder;
    it = m.find((int)temp);
    if (it != m.end()) {
      ret += it->second;
      it->second += 1;
    } else
      m.insert(make_pair((int)temp, 1));
  }
  cout << ret;
}
Problem p02703 (C++) — buggy submission, verdict: Runtime Error

// https://atcoder.jp/contests/abc164/tasks/abc164_e
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int MAX_V = 50;
const int MAX_S = 50 * MAX_V;
const ll INF = 1e18;

struct Edge {
  int to, a, b;
  Edge(int to, int a, int b) : to(to), a(a), b(b) {}
};

struct Data {
  int v, s;
  ll x;
  Data(int v, int s, ll x) : v(v), s(s), x(x) {}
  bool operator<(const Data &r) const { return x > r.x; }
};

vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S + 5];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m, s;
  cin >> n >> m >> s;
  rep(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
  }
  vector<int> c(n), d(n);
  rep(i, n) cin >> c[i] >> d[i];
  rep(i, n) rep(j, MAX_S + 5) dp[i][j] = INF;

  priority_queue<Data> q;
  auto push = [&](int v, int s, ll x) {
    if (s < 0)
      return;
    if (dp[v][s] <= x)
      return;
    dp[v][s] = x;
    q.emplace(v, s, x);
  };
  push(0, min(s, MAX_S), 0);
  while (!q.empty()) {
    Data t = q.top();
    q.pop();
    int v = t.v, s = t.s;
    ll x = t.x;
    // if (dp[v][s] != x) continue;
    push(v, min(s + c[v], MAX_S), x + d[v]);
    for (auto e : g[v]) {
      push(e.to, s - e.a, x + e.b);
    }
  }
  for (int i = 1; i < n; ++i) {
    ll ans = INF;
    rep(j, MAX_S + 5) ans = min(ans, dp[i][j]);
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

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

const int MAX_V = 50;
const int MAX_S = 55 * MAX_V;
const ll INF = 1e18;

struct Edge {
  int to, a, b;
  Edge(int to, int a, int b) : to(to), a(a), b(b) {}
};

struct Data {
  int v, s;
  ll x;
  Data(int v, int s, ll x) : v(v), s(s), x(x) {}
  bool operator<(const Data &r) const { return x > r.x; }
};

vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m, s;
  cin >> n >> m >> s;
  rep(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
  }
  vector<int> c(n), d(n);
  rep(i, n) cin >> c[i] >> d[i];
  rep(i, n) rep(j, MAX_S) dp[i][j] = INF;

  priority_queue<Data> q;
  auto push = [&](int v, int s, ll x) {
    if (s < 0)
      return;
    if (dp[v][s] <= x)
      return;
    dp[v][s] = x;
    q.emplace(v, s, x);
  };
  push(0, min(s, MAX_S), 0);
  while (!q.empty()) {
    Data t = q.top();
    q.pop();
    int v = t.v, s = t.s;
    ll x = t.x;
    if (dp[v][s] != x)
      continue;
    int ns = min(s + c[v], MAX_S);
    push(v, ns, x + d[v]);
    for (auto e : g[v]) {
      push(e.to, s - e.a, x + e.b);
    }
  }
  for (int i = 1; i < n; ++i) {
    ll ans = INF;
    rep(j, MAX_S) ans = min(ans, dp[i][j]);
    cout << ans << endl;
  }
}
Problem p02703 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 55;
const int maxm = 2466;
const ll inf = 0x3f3f3f3f3f3f3f3f;
#define tp tuple<ll, ll, ll>

vector<tp> G[maxn];
ll c[maxn], d[maxn];
ll dp[maxn][maxm];

int main() {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  s = min(2450, s);
  for (int i = 1; i <= m; i++) {
    ll u, v, a, b;
    scanf("%lld%lld%lld%lld", &u, &v, &a, &b);
    G[u].push_back(tp(v, a, b)); // 钱 时间
    G[v].push_back(tp(u, a, b));
  }
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &c[i], &d[i]);
  fill(dp[0], dp[0] + 54 * 2465, inf);
  dp[1][s] = 0;

  priority_queue<tp, vector<tp>, greater<tp>> pq;
  pq.push(tp(0, 1, s));
  while (!pq.empty()) {
    tp cur;
    cur = pq.top();
    pq.pop();
    ll t = get<0>(cur), u = get<1>(cur), w = get<2>(cur);
    for (auto i : G[u]) {
      ll v = get<0>(i), toa = get<1>(i), tob = get<2>(i);
      if (dp[v][w - toa] > t + tob && w >= toa) {
        dp[v][w - toa] = t + tob;
        pq.push(tp(t + tob, v, w - toa));
      }
    }
    if (dp[u][min(2450LL, w + c[u])] > t + d[u]) {
      dp[u][min(2450LL, w + c[u])] = t + d[u];
      pq.push(tp(t + d[u], u, min(2450LL, w + c[u])));
    }
  }
  for (int i = 2; i <= n; i++) {
    ll ans = inf;
    for (int j = 0; j <= 2450; j++) {
      ans = min(ans, dp[i][j]);
    }
    printf("%lld\\n", ans);
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 55;
const int maxm = 2466;
const ll inf = 0x3f3f3f3f3f3f3f3f;
#define tp tuple<ll, ll, ll>

vector<tp> G[maxn];
ll c[maxn], d[maxn];
ll dp[maxn][maxm];

int main() {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    ll u, v, a, b;
    scanf("%lld%lld%lld%lld", &u, &v, &a, &b);
    G[u].push_back(tp(v, a, b)); // 钱 时间
    G[v].push_back(tp(u, a, b));
  }
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &c[i], &d[i]);
  fill(dp[0], dp[0] + 54 * 2460, inf);
  dp[1][s] = 0;

  priority_queue<tp, vector<tp>, greater<tp>> pq;
  pq.push(tp(0, 1, s));
  while (!pq.empty()) {
    tp cur;
    cur = pq.top();
    pq.pop();
    ll t = get<0>(cur), u = get<1>(cur), w = get<2>(cur);
    for (auto i : G[u]) {
      ll v = get<0>(i), toa = get<1>(i), tob = get<2>(i);
      if (dp[v][w - toa] > t + tob && w >= toa) {
        dp[v][w - toa] = t + tob;
        pq.push(tp(t + tob, v, w - toa));
      }
    }
    if (dp[u][min(2450LL, w + c[u])] > t + d[u]) {
      dp[u][min(2450LL, w + c[u])] = t + d[u];
      pq.push(tp(t + d[u], u, min(2450LL, w + c[u])));
    }
  }
  for (int i = 2; i <= n; i++) {
    ll ans = inf;
    for (int j = 0; j <= 2450; j++) {
      ans = min(ans, dp[i][j]);
    }
    printf("%lld\\n", ans);
  }
}