답안 #516013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516013 2022-01-20T09:53:44 Z Jeff12345121 Pinball (JOI14_pinball) C++14
51 / 100
1000 ms 2000 KB
#include <bits/stdc++.h>
#define in cin
#define out cout
#define int long long
using namespace std;

//ifstream in("in.in");
//ofstream out("out.out");

int n, m;
const int inf = (1LL << 60);
struct Dev {
    int l, r, hole, cost;
};
vector<Dev> dev;
template <typename F>
int getDp(vector<int> &dp, F f) {
    /// we want to have all the pinballs take it past left
    // dp[i] = minCost to get all balls to this device
    dp.resize(m + 1);
    for (int i = 1; i <= m; i++) {
        dp[i] = inf;
    }
    int ans = inf;
    for (int i = 1; i <= m; i++) {
        if (f(dev[i])) {
            dp[i] = dev[i].cost;
        }
        for (int j = 1; j < i; j++) {
            if (dev[i].l <= dev[j].hole && dev[j].hole <= dev[i].r) {
                dp[i] = min(dp[i], dp[j] + dev[i].cost);
            }
        }
    }
    return ans;
}
int32_t main() {
    in >> m >> n;
    /// m is number of lines, n is number of collumns

    dev.resize(m + 1);
    for (int i = 1; i <= m; i++) {
        int l, r, hole, cost;
        in >> l >> r >> hole >> cost;
        dev[i] = {l, r, hole, cost};
    }

    vector<int> leftDp, rightDp;
    getDp(leftDp, [&](Dev x) {
        return x.l == 1;
    });

    getDp(rightDp , [&](Dev x) {
        return x.r == n;
    });

    int ans = inf;
    for (int i = 1; i <= m; i++) {
        /// i is middle
        int leftCost = inf, rightCost = inf;
        if (dev[i].l > 1) {
            for (int j = 1; j < i; j++) {
               // if (i == j) continue;

                if (dev[i].l <= dev[j].hole && dev[j].hole <= dev[i].r) {
                    leftCost = min(leftCost, leftDp[j]);
                }
            }
        } else {
            leftCost = 0;
        }

        if (dev[i].r < n) {
            for (int j = 1; j < i; j++) {
                //if (i == j) continue;

                if (dev[i].l <= dev[j].hole && dev[j].hole <= dev[i].r) {
                    rightCost = min(rightCost, rightDp[j]);
                }
            }
        } else {
            rightCost = 0;
        }

        ans = min(ans, leftCost + rightCost + dev[i].cost);
        // cout << "\n";
    }

    if (ans == inf) {
        out << "-1\n";
    } else {
        out << ans << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 10 ms 328 KB Output is correct
18 Correct 10 ms 336 KB Output is correct
19 Correct 10 ms 332 KB Output is correct
20 Correct 13 ms 332 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 8 ms 316 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 7 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 10 ms 328 KB Output is correct
18 Correct 10 ms 336 KB Output is correct
19 Correct 10 ms 332 KB Output is correct
20 Correct 13 ms 332 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 8 ms 316 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 7 ms 332 KB Output is correct
25 Correct 835 ms 1056 KB Output is correct
26 Execution timed out 1062 ms 2000 KB Time limit exceeded
27 Halted 0 ms 0 KB -