Submission #485270

# Submission time Handle Problem Language Result Execution time Memory
485270 2021-11-06T21:38:30 Z MilosMilutinovic Pinball (JOI14_pinball) C++14
100 / 100
617 ms 30676 KB
/**
 *    author: m371
 *    created: 06.11.2021 22:12:33
**/
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;
const int M = 3 * N;
const int MAX = 4 * M;

const long long inf = 1e18;

long long st[MAX];

void build(int x, int l, int r) {
  st[x] = inf;
  if (l == r) return;
  int mid = l + r >> 1;
  build(x + x, l, mid);
  build(x + x + 1, mid + 1, r);
}

void modify(int x, int l, int r, int pos, long long val) {
  if (l == r) {
    st[x] = min(st[x], val);
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid) {
    modify(x + x, l, mid, pos, val);
  } else {
    modify(x + x + 1, mid + 1, r, pos, val);
  }
  st[x] = min(st[x + x], st[x + x + 1]);
}

long long get(int x, int l, int r, int ll, int rr) {
  if (l > r || l > rr || r < ll) return inf;
  if (ll <= l && r <= rr) return st[x];
  int mid = l + r >> 1;
  return min(get(x + x, l, mid, ll, rr), get(x + x + 1, mid + 1, r, ll, rr));
} 

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), cost(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i] >> cost[i];
  }
  vector<int> cs;
  cs.push_back(1);
  cs.push_back(m);
  for (int i = 0; i < n; i++) {
    cs.push_back(a[i]);
    cs.push_back(b[i]);
    cs.push_back(c[i]);
  }
  sort(cs.begin(), cs.end());
  cs.erase(unique(cs.begin(), cs.end()), cs.end());
  map<int, int> val;
  for (int i = 0; i < cs.size(); i++) {
    val[cs[i]] = i;
  }
  build(1, 0, M);
  modify(1, 0, M, val[1], 0);
  vector<long long> L(n), R(n);
  for (int i = 0; i < n; i++) {
    L[i] = get(1, 0, M, val[a[i]], val[b[i]]);
    modify(1, 0, M, val[c[i]], L[i] + cost[i]);
  }
  build(1, 0, M);
  modify(1, 0, M, val[m], 0);
  for (int i = 0; i < n; i++) {
    R[i] = get(1, 0, M, val[a[i]], val[b[i]]);
    modify(1, 0, M, val[c[i]], R[i] + cost[i]);
  }
  long long ans = inf;
  for (int i = 0; i < n; i++) {
    ans = min(ans, L[i] + R[i] + cost[i]);
  }
  cout << (ans == inf ? -1 : ans) << '\n';
  return 0;
}

Compilation message

pinball.cpp: In function 'void build(int, int, int)':
pinball.cpp:20:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |   int mid = l + r >> 1;
      |             ~~^~~
pinball.cpp: In function 'void modify(int, int, int, int, long long int)':
pinball.cpp:30:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |   int mid = l + r >> 1;
      |             ~~^~~
pinball.cpp: In function 'long long int get(int, int, int, int, int)':
pinball.cpp:42:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |   int mid = l + r >> 1;
      |             ~~^~~
pinball.cpp: In function 'int main()':
pinball.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for (int i = 0; i < cs.size(); i++) {
      |                   ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8524 KB Output is correct
2 Correct 6 ms 8524 KB Output is correct
3 Correct 5 ms 8524 KB Output is correct
4 Correct 5 ms 8396 KB Output is correct
5 Correct 5 ms 8524 KB Output is correct
6 Correct 6 ms 8524 KB Output is correct
7 Correct 5 ms 8528 KB Output is correct
8 Correct 5 ms 8524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8524 KB Output is correct
2 Correct 6 ms 8524 KB Output is correct
3 Correct 5 ms 8524 KB Output is correct
4 Correct 5 ms 8396 KB Output is correct
5 Correct 5 ms 8524 KB Output is correct
6 Correct 6 ms 8524 KB Output is correct
7 Correct 5 ms 8528 KB Output is correct
8 Correct 5 ms 8524 KB Output is correct
9 Correct 5 ms 8524 KB Output is correct
10 Correct 6 ms 8524 KB Output is correct
11 Correct 6 ms 8524 KB Output is correct
12 Correct 5 ms 8524 KB Output is correct
13 Correct 6 ms 8500 KB Output is correct
14 Correct 7 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8524 KB Output is correct
2 Correct 6 ms 8524 KB Output is correct
3 Correct 5 ms 8524 KB Output is correct
4 Correct 5 ms 8396 KB Output is correct
5 Correct 5 ms 8524 KB Output is correct
6 Correct 6 ms 8524 KB Output is correct
7 Correct 5 ms 8528 KB Output is correct
8 Correct 5 ms 8524 KB Output is correct
9 Correct 5 ms 8524 KB Output is correct
10 Correct 6 ms 8524 KB Output is correct
11 Correct 6 ms 8524 KB Output is correct
12 Correct 5 ms 8524 KB Output is correct
13 Correct 6 ms 8500 KB Output is correct
14 Correct 7 ms 8568 KB Output is correct
15 Correct 7 ms 8524 KB Output is correct
16 Correct 6 ms 8524 KB Output is correct
17 Correct 7 ms 8636 KB Output is correct
18 Correct 9 ms 8524 KB Output is correct
19 Correct 7 ms 8652 KB Output is correct
20 Correct 7 ms 8524 KB Output is correct
21 Correct 8 ms 8524 KB Output is correct
22 Correct 9 ms 8652 KB Output is correct
23 Correct 7 ms 8632 KB Output is correct
24 Correct 7 ms 8652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8524 KB Output is correct
2 Correct 6 ms 8524 KB Output is correct
3 Correct 5 ms 8524 KB Output is correct
4 Correct 5 ms 8396 KB Output is correct
5 Correct 5 ms 8524 KB Output is correct
6 Correct 6 ms 8524 KB Output is correct
7 Correct 5 ms 8528 KB Output is correct
8 Correct 5 ms 8524 KB Output is correct
9 Correct 5 ms 8524 KB Output is correct
10 Correct 6 ms 8524 KB Output is correct
11 Correct 6 ms 8524 KB Output is correct
12 Correct 5 ms 8524 KB Output is correct
13 Correct 6 ms 8500 KB Output is correct
14 Correct 7 ms 8568 KB Output is correct
15 Correct 7 ms 8524 KB Output is correct
16 Correct 6 ms 8524 KB Output is correct
17 Correct 7 ms 8636 KB Output is correct
18 Correct 9 ms 8524 KB Output is correct
19 Correct 7 ms 8652 KB Output is correct
20 Correct 7 ms 8524 KB Output is correct
21 Correct 8 ms 8524 KB Output is correct
22 Correct 9 ms 8652 KB Output is correct
23 Correct 7 ms 8632 KB Output is correct
24 Correct 7 ms 8652 KB Output is correct
25 Correct 39 ms 9676 KB Output is correct
26 Correct 95 ms 12220 KB Output is correct
27 Correct 333 ms 16396 KB Output is correct
28 Correct 162 ms 16592 KB Output is correct
29 Correct 182 ms 16816 KB Output is correct
30 Correct 240 ms 17488 KB Output is correct
31 Correct 450 ms 24496 KB Output is correct
32 Correct 375 ms 22332 KB Output is correct
33 Correct 54 ms 12816 KB Output is correct
34 Correct 215 ms 19624 KB Output is correct
35 Correct 316 ms 30668 KB Output is correct
36 Correct 617 ms 30676 KB Output is correct
37 Correct 466 ms 30672 KB Output is correct
38 Correct 450 ms 30652 KB Output is correct