답안 #333132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333132 2020-12-04T17:35:33 Z VROOM_VARUN Pinball (JOI14_pinball) C++14
100 / 100
727 ms 52948 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 + 2]);
  }

  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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 5 ms 876 KB Output is correct
23 Correct 3 ms 876 KB Output is correct
24 Correct 3 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 5 ms 876 KB Output is correct
23 Correct 3 ms 876 KB Output is correct
24 Correct 3 ms 876 KB Output is correct
25 Correct 32 ms 3944 KB Output is correct
26 Correct 111 ms 10980 KB Output is correct
27 Correct 390 ms 23396 KB Output is correct
28 Correct 192 ms 16732 KB Output is correct
29 Correct 257 ms 19292 KB Output is correct
30 Correct 276 ms 17492 KB Output is correct
31 Correct 626 ms 36180 KB Output is correct
32 Correct 536 ms 30292 KB Output is correct
33 Correct 68 ms 10604 KB Output is correct
34 Correct 296 ms 26588 KB Output is correct
35 Correct 359 ms 52756 KB Output is correct
36 Correct 727 ms 52820 KB Output is correct
37 Correct 578 ms 52692 KB Output is correct
38 Correct 538 ms 52948 KB Output is correct