Submission #333122

# Submission time Handle Problem Language Result Execution time Memory
333122 2020-12-04T16:46:50 Z VROOM_VARUN Pinball (JOI14_pinball) C++14
0 / 100
1 ms 364 KB
/*
ID: varunra2
LANG: C++
TASK: pinball
*/

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

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define int long long

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (long long)1e16
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions

int n, m;
VVI qrys;
VI dplft;
VI dprt;
VI pnts;

void init() {
  qrys.resize(m);
  trav(x, qrys) x.resize(4);
  dplft.resize(m);
  dprt.resize(m);
}

MPII cmp;
int siz;

void compress() {
  sort(all(pnts));
  pnts.resize(unique(all(pnts)) - pnts.begin());
  rep(i, 0, sz(pnts)) cmp[pnts[i]] = i;
  siz = sz(pnts);
}

struct segtree {
  VI st;

  void init() { st.assign(4 * siz, INF); }

  void upd(int ind, int val, int node, int l, int r) {
    if (ind < l or ind > r) return;
    if (ind == l and ind == r) {
      st[node] = min(st[node], val);
      return;
    }

    int mid = (l + r) / 2;
    upd(ind, val, 2 * node + 1, l, mid);
    upd(ind, val, 2 * node + 2, mid + 1, r);
    st[node] = min(st[2 * node + 1], st[2 * node + 1]);
  }

  int qry(int tl, int tr, int node, int l, int r) {
    if (tl > r or tr < l) return INF;
    if (l >= tl and r <= tr) return st[node];
    if (l > r) return INF;
    int mid = (l + r) / 2;
    return min(qry(tl, tr, 2 * node + 1, l, mid),
               qry(tl, tr, 2 * node + 2, mid + 1, r));
  }

  void upd(int ind, int val) { upd(ind, val, 0, 0, siz - 1); }

  int qry(int l, int r) { return qry(l, r, 0, 0, siz - 1); }
} lft, rt;

int32_t main() {
  // #ifndef ONLINE_JUDGE
  // freopen("pinball.in", "r", stdin);
  // freopen("pinball.out", "w", stdout);
  // #endif
  cin.sync_with_stdio(0);
  cin.tie(0);

  cin >> m >> n;

  init();
  int sum = 0;

  rep(i, 0, m) {
    rep(j, 0, 3) {
      int val;
      cin >> val;
      qrys[i][j] = val;
      pnts.PB(val);
    }
    cin >> qrys[i][3];
    sum += qrys[i][3];
  }

  compress();

  lft.init();
  rt.init();

  int ret = INF;

  for (int i = 0; i < m; i++) {
    int a, b, c;
    a = cmp[qrys[i][0]], b = cmp[qrys[i][1]], c = cmp[qrys[i][2]];
    dplft[i] = lft.qry(a, b);
    dprt[i] = rt.qry(a, b);
    if (qrys[i][0] == 1) dplft[i] = 0;
    if (qrys[i][1] == n) dprt[i] = 0;
    ret = min(ret, dplft[i] + dprt[i] + qrys[i][3]);
    dplft[i] += qrys[i][3];
    dprt[i] += qrys[i][3];
    lft.upd(c, dplft[i]);
    rt.upd(c, dprt[i]);
  }

  if (ret > sum)
    cout << -1 << '\n';
  else
    cout << ret << '\n';

  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -