Submission #1068919

# Submission time Handle Problem Language Result Execution time Memory
1068919 2024-08-21T13:12:33 Z Boycl07 Pinball (JOI14_pinball) C++17
0 / 100
2 ms 1884 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;

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

    SegTree(int len) : n(len) {}

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

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

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

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));

    SegTree St_left(n), St_right(n);
    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]);
    }

    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:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen("note.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Incorrect 1 ms 1884 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Incorrect 1 ms 1884 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Incorrect 1 ms 1884 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Incorrect 1 ms 1884 KB Output isn't correct
8 Halted 0 ms 0 KB -