답안 #366593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366593 2021-02-14T18:35:50 Z parsabahrami Pinball (JOI14_pinball) C++17
100 / 100
452 ms 25964 KB
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second
#define lc                          id << 1
#define rc                          lc | 1

const int N = 3e5 + 10;
ll seg[2][N << 2], ret = 1e18; int n, m, A[N], B[N], C[N], D[N];
vector<int> vec;

void upd(int p, ll x, int t, int id = 1, int l = 0, int r = SZ(vec)) {
    if (r - l < 2) {
        seg[t][id] = min(seg[t][id], x);
        return;
    }
    int mid = (l + r) >> 1;
    if (p < mid) upd(p, x, t, lc, l, mid);
    else upd(p, x, t, rc, mid, r);
    seg[t][id] = min(seg[t][lc], seg[t][rc]);
}

ll get(int ql, int qr, int t, int id = 1, int l = 0, int r = SZ(vec)) {
    if (qr <= l || r <= ql) return 1e18;
    if (ql <= l && r <= qr) return seg[t][id];
    int mid = (l + r) >> 1;
    return min(get(ql, qr, t, lc, l, mid), get(ql, qr, t, rc, mid, r));
}

int main() {
    scanf("%d%d", &m, &n);
    if (n == 1) return !printf("0\n");
    for (int i = 1; i <= m; i++) {
        scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
        vec.push_back(A[i]);
        vec.push_back(B[i]);
        vec.push_back(C[i]);
    }
    sort(vec.begin(), vec.end());
    vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
    if (vec.back() < n || vec[0] > 1) return !printf("-1\n");
    fill(seg[0], seg[0] + N * 4, 1e18), fill(seg[1], seg[1] + N * 4, 1e18);
    upd(0, 0, 0), upd(SZ(vec) - 1, 0, 1);
    for (int i = 1; i <= m; i++) {
        int a = lower_bound(vec.begin(), vec.end(), A[i]) - vec.begin();
        int b = lower_bound(vec.begin(), vec.end(), B[i]) - vec.begin();
        int c = lower_bound(vec.begin(), vec.end(), C[i]) - vec.begin();
        int d = D[i];
        upd(c, get(a, b + 1, 0) + d, 0), upd(c, get(a, b + 1, 1) + d, 1);
        //printf("%lld %lld\n", get(c, c + 1, 0), get(c, c + 1, 1));
        ret = min(ret, d + get(a, b + 1, 0) + get(a, b + 1, 1));
    }
    printf("%lld\n", ret == 1e18 ? -1 : ret);
    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("%d%d", &m, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~
pinball.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |         scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19180 KB Output is correct
2 Correct 10 ms 19180 KB Output is correct
3 Correct 10 ms 19180 KB Output is correct
4 Correct 10 ms 19180 KB Output is correct
5 Correct 10 ms 19180 KB Output is correct
6 Correct 11 ms 19180 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 10 ms 19180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19180 KB Output is correct
2 Correct 10 ms 19180 KB Output is correct
3 Correct 10 ms 19180 KB Output is correct
4 Correct 10 ms 19180 KB Output is correct
5 Correct 10 ms 19180 KB Output is correct
6 Correct 11 ms 19180 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 10 ms 19180 KB Output is correct
9 Correct 11 ms 19180 KB Output is correct
10 Correct 11 ms 19180 KB Output is correct
11 Correct 12 ms 19180 KB Output is correct
12 Correct 11 ms 19180 KB Output is correct
13 Correct 12 ms 19180 KB Output is correct
14 Correct 11 ms 19180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19180 KB Output is correct
2 Correct 10 ms 19180 KB Output is correct
3 Correct 10 ms 19180 KB Output is correct
4 Correct 10 ms 19180 KB Output is correct
5 Correct 10 ms 19180 KB Output is correct
6 Correct 11 ms 19180 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 10 ms 19180 KB Output is correct
9 Correct 11 ms 19180 KB Output is correct
10 Correct 11 ms 19180 KB Output is correct
11 Correct 12 ms 19180 KB Output is correct
12 Correct 11 ms 19180 KB Output is correct
13 Correct 12 ms 19180 KB Output is correct
14 Correct 11 ms 19180 KB Output is correct
15 Correct 10 ms 19188 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 13 ms 19180 KB Output is correct
18 Correct 12 ms 19180 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 15 ms 19308 KB Output is correct
21 Correct 11 ms 19180 KB Output is correct
22 Correct 13 ms 19180 KB Output is correct
23 Correct 13 ms 19180 KB Output is correct
24 Correct 12 ms 19180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19180 KB Output is correct
2 Correct 10 ms 19180 KB Output is correct
3 Correct 10 ms 19180 KB Output is correct
4 Correct 10 ms 19180 KB Output is correct
5 Correct 10 ms 19180 KB Output is correct
6 Correct 11 ms 19180 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 10 ms 19180 KB Output is correct
9 Correct 11 ms 19180 KB Output is correct
10 Correct 11 ms 19180 KB Output is correct
11 Correct 12 ms 19180 KB Output is correct
12 Correct 11 ms 19180 KB Output is correct
13 Correct 12 ms 19180 KB Output is correct
14 Correct 11 ms 19180 KB Output is correct
15 Correct 10 ms 19188 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 13 ms 19180 KB Output is correct
18 Correct 12 ms 19180 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 15 ms 19308 KB Output is correct
21 Correct 11 ms 19180 KB Output is correct
22 Correct 13 ms 19180 KB Output is correct
23 Correct 13 ms 19180 KB Output is correct
24 Correct 12 ms 19180 KB Output is correct
25 Correct 38 ms 19820 KB Output is correct
26 Correct 92 ms 20836 KB Output is correct
27 Correct 306 ms 23668 KB Output is correct
28 Correct 215 ms 25820 KB Output is correct
29 Correct 190 ms 22496 KB Output is correct
30 Correct 308 ms 25964 KB Output is correct
31 Correct 435 ms 25948 KB Output is correct
32 Correct 415 ms 25948 KB Output is correct
33 Correct 57 ms 20456 KB Output is correct
34 Correct 205 ms 22496 KB Output is correct
35 Correct 262 ms 25820 KB Output is correct
36 Correct 452 ms 25948 KB Output is correct
37 Correct 383 ms 25900 KB Output is correct
38 Correct 351 ms 25956 KB Output is correct