Submission #524999

# Submission time Handle Problem Language Result Execution time Memory
524999 2022-02-10T12:46:05 Z codelegend Pinball (JOI14_pinball) C++14
11 / 100
1000 ms 316 KB
/**
 * 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

pinball.cpp: In function 'void solve(std::istream&, std::ostream&)':
pinball.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |   for (auto &[a, b, c, d] : devices) cin >> a >> b >> c >> d;
      |              ^
pinball.cpp:38:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |           auto [a, b, c, d] = devices[i];
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 3 ms 308 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 10 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 3 ms 308 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 10 ms 312 KB Output is correct
9 Execution timed out 1085 ms 316 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 3 ms 308 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 10 ms 312 KB Output is correct
9 Execution timed out 1085 ms 316 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 3 ms 308 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 10 ms 312 KB Output is correct
9 Execution timed out 1085 ms 316 KB Time limit exceeded
10 Halted 0 ms 0 KB -