답안 #508722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
508722 2022-01-13T15:57:03 Z Jeff12345121 Pinball (JOI14_pinball) C++14
11 / 100
1000 ms 94188 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");

struct device {
    int l, r, hole, cost;
};
vector<device> devices;
const int nmax = 20, mmax = 1005, inf = (1LL << 60);
int n, m, dp[nmax][mmax][mmax];
void minSelf(int &a, int b) {
    if (b < a) {
        a = b;
    }
}
int ans = inf;

void check(int mask) {
    set<int> s;
    for (int i = 1; i <= m; i++) {
        s.insert(i);
    }

    int cost = 0;
    for (int i = 0; i < n; i++) {
        set<int> s2;
        if (mask & (1 << i)) cost += devices[i + 1].cost;
        for (auto k : s) {
            if ( (mask & (1 << i)) && (devices[i + 1].l <= k && k <= devices[i + 1].r) ) {
                    s2.insert(devices[i + 1].hole);
                }
            else {
                s2.insert(k);
            }
        }
        s = s2;
    }
    if (s.size() == 1) {
        ans = min(ans, cost);
    }
}
int32_t main() {
    in >> n >> m;
    if (m == 1) {
        out << "0\n";
        return 0;
    }
    devices.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        int l, r, hole, cost;
        in >> l >> r >> hole >> cost;
        devices[i] = {l, r, hole, cost};
    }

    for (int mask = 0; mask < (1 << n); mask++) {
        check(mask);
    }

    if (ans == inf) {
        out << "-1\n";
    } else {
        out << ans << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 65 ms 288 KB Output is correct
4 Correct 227 ms 328 KB Output is correct
5 Correct 864 ms 376 KB Output is correct
6 Correct 42 ms 284 KB Output is correct
7 Correct 531 ms 376 KB Output is correct
8 Correct 370 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 65 ms 288 KB Output is correct
4 Correct 227 ms 328 KB Output is correct
5 Correct 864 ms 376 KB Output is correct
6 Correct 42 ms 284 KB Output is correct
7 Correct 531 ms 376 KB Output is correct
8 Correct 370 ms 376 KB Output is correct
9 Execution timed out 1085 ms 94188 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 65 ms 288 KB Output is correct
4 Correct 227 ms 328 KB Output is correct
5 Correct 864 ms 376 KB Output is correct
6 Correct 42 ms 284 KB Output is correct
7 Correct 531 ms 376 KB Output is correct
8 Correct 370 ms 376 KB Output is correct
9 Execution timed out 1085 ms 94188 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 65 ms 288 KB Output is correct
4 Correct 227 ms 328 KB Output is correct
5 Correct 864 ms 376 KB Output is correct
6 Correct 42 ms 284 KB Output is correct
7 Correct 531 ms 376 KB Output is correct
8 Correct 370 ms 376 KB Output is correct
9 Execution timed out 1085 ms 94188 KB Time limit exceeded
10 Halted 0 ms 0 KB -