| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 524999 | codelegend | Pinball (JOI14_pinball) | C++14 | 1085 ms | 316 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author codelegend
 */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)
#define SZ(v) ((int)size(v))
void prec() {}
void solve(istream &cin, ostream &cout) {
  int m, n;
  cin >> m >> n;
  vector<array<int, 4>> devices(m);
  for (auto &[a, b, c, d] : devices) cin >> a >> b >> c >> d;
  const ll inf = numeric_limits<ll>::max();
  ll best = inf;
  for (int mask = 0; mask < (1 << m); mask++) {
    ll cost = 0;
    for (int i = 0; i < m; i++) {
      if (mask & (1 << i)) cost += devices[i][3];
    }
    int fin = -1;
    bool ok = true;
    for (int s = 1; s <= n; s++) {
      int x = s;
      for (int i = 0; i < m; i++) {
        if (mask & (1 << i)) {
          auto [a, b, c, d] = devices[i];
          if (a <= x && x <= b) x = c;
        }
      }
      if (fin == -1) fin = x;
      if (fin != x) {
        ok = false;
        break;
      }
    }
    if (ok) best = min(best, cost);
  }
  if (best == inf) best = -1;
  cout << best << '\n';
}
//====== Submission Template; Ignore ========//
struct Pinball {
  void solve(std::istream &in, std::ostream &out) { ::solve(in, out); }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  prec();
  Pinball solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
