답안 #908695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908695 2024-01-16T16:52:39 Z vjudge1 Pinball (JOI14_pinball) C++17
100 / 100
157 ms 31856 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 1e5 + 7;
const ll INF = 1e18;
int rows, cols;

struct kek {
    ll l;
    ll r;
    ll c;
    ll d;
};

kek a[N];
ll aib1[3 * N], aib2[3 * N];
ll dp1[N], dp2[N];

void update1(int i, ll val) {
    for (; i < 3 * N; i += i & -i) aib1[i] = min(aib1[i], val);
}

void update2(int i, ll val) {
    for (; i >= 1; i -= i & -i) aib2[i] = min(aib2[i], val);
}

ll query1(int i) {
    ll ans = INF;
    for (; i >= 1; i -= i & -i) ans = min(ans, aib1[i]);
    return ans;
}

ll query2(int i) {
    ll ans = INF;
    for (; i < 3 * N; i += i & -i) ans = min(ans, aib2[i]);
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> rows >> cols;
    for (int i = 1; i <= rows; ++i) cin >> a[i].l >> a[i].r >> a[i].c >> a[i].d; 
    bool ok = 0;
    for (int i = 1; i <= rows; ++i) ok |= (a[i].l == 1);
    if (!ok) {
        cout << "-1\n";
        return 0;
    }
    ok = 0;
    for (int i = 1; i <= rows; ++i) ok |= (a[i].r == cols);
    if (!ok) {
        cout << "-1\n";
        return 0;
    }
    {
        vector<vector<int>> vals;
        for (int i = 1; i <= rows; ++i) {
            vals.push_back({a[i].l, 0, i});
            vals.push_back({a[i].r, 1, i});
            vals.push_back({a[i].c, 2, i});
        }
        sort(vals.begin(), vals.end());
        //cout << "DEBUG: " << "\n";
        //for (auto it : vals) {
            //cout << it[0] << " " << it[1] << " " << it[2] << "\n";
        //}
        int cnt = 1;
        for (int i = 0; i < vals.size(); ++i) {
            if (i > 0 && vals[i][0] != vals[i - 1][0]) ++cnt;
            auto it = vals[i];
            if (it[1] == 0) a[it[2]].l = cnt; 
            if (it[1] == 1) a[it[2]].r = cnt;
            if (it[1] == 2) a[it[2]].c = cnt;
        }
    }
    //cout << "DEBUG: " << "\n";
    //for (int i = 1; i <= rows; ++i) {
        //cout << a[i].l << " " << a[i].r << " " << a[i].c << "\n";
    //}
    ll mx = 0;
    for (int i = 1; i <= rows; ++i) {
        mx = max(mx, a[i].l);
        mx = max(mx, a[i].r);
        mx = max(mx, a[i].c);
        dp1[i] = INF;
        dp2[i] = INF;
    }
    for (int i = 1; i < 3 * N; ++i) {
        aib1[i] = INF;
        aib2[i] = INF;
    }
    for (int i = 1; i <= rows; ++i) {
        if (a[i].l == 1) dp1[i] = a[i].d;
        if (a[i].r == mx) dp2[i] = a[i].d;
    }
    //for (int i = 1; i <= rows; ++i) cout << dp1[i] << " " << dp2[i] << "\n";
    //cout << "-------\n";
    ll ans = INF;
    for (int i = 1; i <= rows; ++i) {
        //if (i == 3) {
            //cout << query2(a[i].l) << "\n"; 
        //}
        dp1[i] = min(dp1[i], query2(a[i].l) + a[i].d);
        dp2[i] = min(dp2[i], query1(a[i].r) + a[i].d);
        //cout << "UPDATAM " << a[i].c << " " << dp1[i] << "\n";
        update2(a[i].c, dp1[i]);
        update1(a[i].c, dp2[i]);
        ans = min(ans, dp1[i] + dp2[i] - a[i].d);
        //cout << dp1[i] << " " << dp2[i] << "\n";
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:61:34: warning: narrowing conversion of 'a[i].kek::l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   61 |             vals.push_back({a[i].l, 0, i});
      |                             ~~~~~^
pinball.cpp:61:34: warning: narrowing conversion of 'a[i].kek::l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
pinball.cpp:62:34: warning: narrowing conversion of 'a[i].kek::r' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   62 |             vals.push_back({a[i].r, 1, i});
      |                             ~~~~~^
pinball.cpp:62:34: warning: narrowing conversion of 'a[i].kek::r' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
pinball.cpp:63:34: warning: narrowing conversion of 'a[i].kek::c' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   63 |             vals.push_back({a[i].c, 2, i});
      |                             ~~~~~^
pinball.cpp:63:34: warning: narrowing conversion of 'a[i].kek::c' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
pinball.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for (int i = 0; i < vals.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6672 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6672 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 3 ms 6652 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 3 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6672 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 3 ms 6652 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 3 ms 6748 KB Output is correct
25 Correct 11 ms 9812 KB Output is correct
26 Correct 27 ms 12072 KB Output is correct
27 Correct 79 ms 18660 KB Output is correct
28 Correct 153 ms 30684 KB Output is correct
29 Correct 56 ms 17256 KB Output is correct
30 Correct 157 ms 31280 KB Output is correct
31 Correct 141 ms 29952 KB Output is correct
32 Correct 131 ms 31856 KB Output is correct
33 Correct 24 ms 11340 KB Output is correct
34 Correct 51 ms 17908 KB Output is correct
35 Correct 85 ms 31732 KB Output is correct
36 Correct 147 ms 30192 KB Output is correct
37 Correct 123 ms 30204 KB Output is correct
38 Correct 116 ms 31080 KB Output is correct