답안 #503782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503782 2022-01-08T21:55:54 Z colossal_pepe Pinball (JOI14_pinball) C++17
29 / 100
1000 ms 96300 KB
#include <iostream>
#include <map>
#include <tuple>
using namespace std;

typedef long long ll;

const ll INF = 1e18;

int n, m, a[1005], b[1005], c[1005];
ll d[1005];
map<tuple<int, int, int>, ll> dp;

ll brutus(int i, int l, int r) {
    if (l == r) return 0;
    if (i >= n) return INF;
    if (dp.find({i, l, r}) != dp.end()) return dp[{i, l, r}];
    ll ans = INF;
    ans = min(ans, brutus(i + 1, l, r));
    if (a[i] <= l and b[i] >= r) {
        ans = min(ans, brutus(i + 1, c[i], c[i]) + d[i]);
    } else if (a[i] <= l) {
        ans = min(ans, brutus(i + 1, c[i], r) + d[i]);
    } else if (b[i] >= r) {
        ans = min(ans, brutus(i + 1, l, c[i]) + d[i]);
    }
    dp[{i, l, r}] = ans;
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    brutus(0, 1, m);
    cout << (dp[{0, 1, m}] >= INF ? -1 : dp[{0, 1, m}]) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 59 ms 6316 KB Output is correct
10 Correct 138 ms 14004 KB Output is correct
11 Correct 119 ms 13632 KB Output is correct
12 Correct 3 ms 972 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 4 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 59 ms 6316 KB Output is correct
10 Correct 138 ms 14004 KB Output is correct
11 Correct 119 ms 13632 KB Output is correct
12 Correct 3 ms 972 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 4 ms 1484 KB Output is correct
15 Correct 13 ms 1996 KB Output is correct
16 Correct 5 ms 1100 KB Output is correct
17 Execution timed out 1076 ms 96300 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 59 ms 6316 KB Output is correct
10 Correct 138 ms 14004 KB Output is correct
11 Correct 119 ms 13632 KB Output is correct
12 Correct 3 ms 972 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 4 ms 1484 KB Output is correct
15 Correct 13 ms 1996 KB Output is correct
16 Correct 5 ms 1100 KB Output is correct
17 Execution timed out 1076 ms 96300 KB Time limit exceeded
18 Halted 0 ms 0 KB -