답안 #584554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584554 2022-06-27T14:34:08 Z drdilyor Pinball (JOI14_pinball) C++17
11 / 100
1000 ms 15956 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())
#define cut(s) {cout << s << '\n'; return 0;}

using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K> using ordered_set = pd::tree<K, pd::null_type, less<K>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T> using hash_table = pd::gp_hash_table<T...>;

const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
const int INF = 1e9;
const ll INFL = 1e18;
const int N = 1000;
const int M = 10;

struct device {
    int left, right, center, cost;
};
ostream& operator <<(ostream& os, device& a) {
    return os << "{" << a.left << "," << a.right << ", " << a.center << " $" << a.cost << "}";
}

struct SegTree {
    int n;
    vector<ll> tree;
    SegTree(int n) : n(n), tree(2*n, INFL) {}
    void update(int i, ll v) {
        i += n;
        tree[i] = min(tree[i], v);
        for (; i >= 1; i >>= 1) tree[i] = min(tree[i>>1], tree[i>>1|1]);
    }
    ll query(int l, int r) {
        ll res = INFL;
        while (l <= r) {
            if (l&2) res = min(res, tree[l++]);
            if (~r&2) res = min(res, tree[r--]);
            l >>= 1; r >>= 1;
        }
        return res;
    }
};

int solve() {
    int n, m;
    cin >> m >> n;
    vector<device> dev(m);

    for (int i = 0; i < m; i++) {
        cin >> dev[i].left >> dev[i].right >> dev[i].center >> dev[i].cost;
        dev[i].left--; dev[i].right--; dev[i].center--;
    }

    /*{
        //compress
        vi values;
        for (int i = 0; i < m; i++) {
            values.push_back(dev[i].left);
            values.push_back(dev[i].right);
            values.push_back(dev[i].center);
        }
        sort(allit(values));
        map<int,int> mapping;
        int key = -1;
        for (int i = 0; i < sz(values); i++) {
            if (i && values[i-1] == values[i])
                continue;
            mapping[values[i]] = ++key;
        }

        for (int i = 0; i < m; i++) {
            dev[i].left = mapping[dev[i].left];
            dev[i].right = mapping[dev[i].right];
            dev[i].center = mapping[dev[i].center];
        }
        n = key+1;
    }*/

    vector<ll> mnLeft(n+10), mnRight(n+10);

    function<ll(int)> dpLeft = [&](int i) {
        ll res = INFL;
        if (dev[i].left == 0) res = (ll)dev[i].cost;
        else {
            for (int j = 0; j < i; j++) {
                if (dev[i].left <= dev[j].center && dev[j].center <= dev[i].right)
                    res = min(res, dpLeft(j));
            }
            res += dev[i].cost;
        }
        return res;
    };

    function<ll(int)> dpRight = [&](int i) {
        ll res = INFL;
        if (dev[i].right == n-1) res = dev[i].cost;
        else {
            for (int j = 0; j < i; j++) {
                if (dev[i].left <= dev[j].center && dev[j].center <= dev[i].right)
                    res = min(res, dpRight(j));
            }
            res += dev[i].cost;
        }
        return res;
    };

    ll res = INFL;
    for (int i = 0; i < m; i++) {
        ll l = dpLeft(i), r = dpRight(i);
        debug(i, l, r);
        if (l < INFL && r < INFL)
            res = min(res, l + r - dev[i].cost);
    }
    cout << (res >= INFL ? -1 : res);

    return 0;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}

Compilation message

pinball.cpp: In function 'int solve()':
pinball.cpp:7:24: warning: statement has no effect [-Wunused-value]
    7 |     #define debug(...) 42
      |                        ^~
pinball.cpp:120:9: note: in expansion of macro 'debug'
  120 |         debug(i, l, r);
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Execution timed out 1093 ms 15956 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Execution timed out 1093 ms 15956 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Execution timed out 1093 ms 15956 KB Time limit exceeded
10 Halted 0 ms 0 KB -