Submission #1068925

# Submission time Handle Problem Language Result Execution time Memory
1068925 2024-08-21T13:19:44 Z Boycl07 Pinball (JOI14_pinball) C++17
100 / 100
99 ms 11484 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "FFILL"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }


const int N = 1e5 + 3;
const int LIM = (1 << 16) + 3;
const ll INF = 1e18 + 1;
const int LOG = 19;

int s;

struct SegTree
{
    ll st[N << 1];
    int n;

    void init()
    {
        rep(i, 2 * s) st[i] = INF;
    }

    void update(int pos, ll val)
    {
        for(minimize(st[pos += s], val); pos >>= 1; ) st[pos] = min(st[pos << 1], st[pos << 1 | 1]);
    }

    ll get(int l, int r)
    {
        ll res = INF;
        for(l += s, r += s + 1; l < r; l >>= 1, r >>= 1)
        {
            if(l & 1) minimize(res, st[l++]);
            if(r & 1) minimize(res, st[--r]);
        }
        return res;
    }
} St_left, St_right;

int n, m;

int a[N], b[N], c[N], d[N];

vector<int> zip;

void solve()
{
    cin >> n >> m;
    rep(i, n) cin >> a[i] >> b[i] >> c[i] >> d[i], zip.pb(c[i]);
    sort(all(zip));
    zip.resize(unique(all(zip)) - zip.begin());
    s = sz(zip);
    St_left.init();
    St_right.init();

    ll res = INF;

    rep(i, n)
    {
        int l = lower_bound(all(zip), a[i]) - zip.begin() + 1;
        int r = upper_bound(all(zip), b[i]) - zip.begin();
        int x = lower_bound(all(zip), c[i]) - zip.begin() + 1;

        ll cost_l = min((a[i] == 1 ? 0 : INF), St_left.get(l, r));
        ll cost_r = min((b[i] == m ? 0 : INF), St_right.get(l, r));
        minimize(res, d[i] + cost_l + cost_r);
        St_left.update(x, cost_l + d[i]);
        St_right.update(x, cost_r + d[i]);
    }

    if(res == INF) cout << -1;
    else cout << res;

}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int TC = 1;

    if(fopen("note.inp", "r"))
    {
        freopen("note.inp", "r", stdin);
        freopen("note.out", "w", stdout);
    }


    while(TC--)
    {
        solve();
    }

    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         freopen("note.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pinball.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen("note.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4448 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4448 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4572 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4624 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 2588 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4448 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4572 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4624 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 2588 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 8 ms 5208 KB Output is correct
26 Correct 21 ms 6108 KB Output is correct
27 Correct 65 ms 8412 KB Output is correct
28 Correct 59 ms 9420 KB Output is correct
29 Correct 43 ms 7592 KB Output is correct
30 Correct 74 ms 9676 KB Output is correct
31 Correct 94 ms 10508 KB Output is correct
32 Correct 99 ms 10188 KB Output is correct
33 Correct 14 ms 5852 KB Output is correct
34 Correct 45 ms 7896 KB Output is correct
35 Correct 56 ms 11472 KB Output is correct
36 Correct 96 ms 11468 KB Output is correct
37 Correct 74 ms 11484 KB Output is correct
38 Correct 72 ms 11472 KB Output is correct