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

#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for (ll i = l; i < (ll)r; i++)
#define per(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define per3(i, l, r) for (ll i = (ll)r - 1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template <class T, class U> inline void cmax(T &a, U b) {
  if (a < b)
    a = b;
}
template <class T, class U> inline void cmin(T &a, U b) {
  if (a > b)
    a = b;
}
constexpr char el = '\\n';
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v)
    is >> in;
  return is;
}
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;
#line 3 "../../library/debug.hpp"

// https://codeforces.com/blog/entry/68809
void debug_print(int x) { cerr << x; }
void debug_print(long x) { cerr << x; }
void debug_print(long long x) { cerr << x; }
void debug_print(unsigned x) { cerr << x; }
void debug_print(unsigned long x) { cerr << x; }
void debug_print(unsigned long long x) { cerr << x; }
void debug_print(float x) { cerr << x; }
void debug_print(double x) { cerr << x; }
void debug_print(long double x) { cerr << x; }
void debug_print(char x) { cerr << '\\'' << x << '\\''; }
void debug_print(const char *x) { cerr << '\\"' << x << '\\"'; }
void debug_print(const string &x) { cerr << '\\"' << x << '\\"'; }
void debug_print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void debug_print(const pair<T, V> &x) {
  cerr << '{';
  debug_print(x.first);
  cerr << ',';
  debug_print(x.second);
  cerr << '}';
}
template <typename T> void debug_print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), debug_print(i);
  cerr << "}";
}

void debug_print_() { cerr << "]\\n"; }
template <typename T, typename... V> void debug_print_(T t, V... v) {
  debug_print(t);
  if (sizeof...(v))
    cerr << ", ";
  debug_print_(v...);
}

#ifdef LOCAL
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  debug_print_(x)
#else
#define debug(x...)
#endif
#line 3 "c.cpp"

ll ans = 0;
ll n, m, q = 50;

vl a(q);
vl b(q);
vl c(q);
vl d(q);

ll solve(vl &vec) {
  debug(vec);
  ll score = 0;
  rep(i, q) {
    if (vec[b[i] - 1] - vec[a[i] - 1] == c[i]) {
      score += d[i];
    }
  }
  return score;
}

void dfs(ll cn, vl &vec) {
  if (cn == n) {
    cmax(ans, solve(vec));
  } else {
    rep3(i, vec[cn - 1], m + 1) {
      vec[cn] = i;
      dfs(cn + 1, vec);
    }
  }
}

int main() {
  cin >> n >> m >> q;

  rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; }

  vl vec(n);
  rep3(i, 1, m + 1) {
    vec[0] = i;
    dfs(1, vec);
  }

  cout << ans << el;
}


Error: 0

Fixed submission:

#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for (ll i = l; i < (ll)r; i++)
#define per(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define per3(i, l, r) for (ll i = (ll)r - 1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template <class T, class U> inline void cmax(T &a, U b) {
  if (a < b)
    a = b;
}
template <class T, class U> inline void cmin(T &a, U b) {
  if (a > b)
    a = b;
}
constexpr char el = '\\n';
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v)
    is >> in;
  return is;
}
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;
#line 3 "../../library/debug.hpp"

// https://codeforces.com/blog/entry/68809
void debug_print(int x) { cerr << x; }
void debug_print(long x) { cerr << x; }
void debug_print(long long x) { cerr << x; }
void debug_print(unsigned x) { cerr << x; }
void debug_print(unsigned long x) { cerr << x; }
void debug_print(unsigned long long x) { cerr << x; }
void debug_print(float x) { cerr << x; }
void debug_print(double x) { cerr << x; }
void debug_print(long double x) { cerr << x; }
void debug_print(char x) { cerr << '\\'' << x << '\\''; }
void debug_print(const char *x) { cerr << '\\"' << x << '\\"'; }
void debug_print(const string &x) { cerr << '\\"' << x << '\\"'; }
void debug_print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void debug_print(const pair<T, V> &x) {
  cerr << '{';
  debug_print(x.first);
  cerr << ',';
  debug_print(x.second);
  cerr << '}';
}
template <typename T> void debug_print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), debug_print(i);
  cerr << "}";
}

void debug_print_() { cerr << "]\\n"; }
template <typename T, typename... V> void debug_print_(T t, V... v) {
  debug_print(t);
  if (sizeof...(v))
    cerr << ", ";
  debug_print_(v...);
}

#ifdef LOCAL
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  debug_print_(x)
#else
#define debug(x...)
#endif
#line 3 "c.cpp"

ll ans = 0;
ll n, m, q = 10;

vl a(q);
vl b(q);
vl c(q);
vl d(q);

ll solve(vl &vec) {
  ll score = 0;
  rep(i, q) {
    if (vec[b[i] - 1] - vec[a[i] - 1] == c[i]) {
      score += d[i];
    }
  }
  return score;
}

void dfs(ll cn, vl &vec) {
  if (cn == m) {
    cmax(ans, solve(vec));
  } else {
    rep3(i, vec[cn - 1], m + 1) {
      vec[cn] = i;
      dfs(cn + 1, vec);
    }
  }
}

int main() {
  cin >> n >> m >> q;

  rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; }

  vl vec(m);
  rep3(i, 1, m + 1) {
    vec[0] = i;
    dfs(1, vec);
  }

  cout << ans << el;
}