답안 #1068923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068923 2024-08-21T13:18:39 Z Boycl07 Pinball (JOI14_pinball) C++17
0 / 100
1 ms 4444 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]);
    }

    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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Incorrect 1 ms 4444 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Incorrect 1 ms 4444 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Incorrect 1 ms 4444 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Incorrect 1 ms 4444 KB Output isn't correct
8 Halted 0 ms 0 KB -