답안 #575022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575022 2022-06-09T14:18:39 Z MadokaMagicaFan Pinball (JOI14_pinball) C++14
100 / 100
469 ms 22592 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
const ll inf = 1e17;
const int md1 = 1e9+7;
const int md2 = 998244353;

#define sz(v)                       ((int)v.size())
#define pb                          push_back

#define pry                         cout << "YES\n"
#define prn                         cout << "NO\n"
#define endl                        '\n'

#define fst                         first
#define scn                         second
#define ONPC

const int N = 1e9+1;

struct d{
    int l, r;
    int out;
    ll p;
};

struct SGT{
    int n;
    vector<ll> t;

    SGT(int _n)
    {
        n = _n;
        t.assign(4 * n,inf);
    }

    void
    update(int i, int l, int r, ll x, int tg)
    {
        if (l > tg || r < tg) return;
        if (l == r) {
            t[i] = min(t[i],x);
            return;
        }
        int mid = (l+r)>>1;
        update(i<<1,l,mid,x,tg);
        update(i<<1|1,mid+1,r,x,tg);

        t[i] = min(t[i<<1],t[i<<1|1]);
        return;
    }

    ll
    query(int i, int l, int r, int tl, int tr)
    {
        if (l > tr || r < tl) return inf;
        if (l >= tl && r <= tr) return t[i];
        if (l == r) return t[i];
        int mid = (l+r)>>1;
        return min(
                query(i<<1,l,mid,tl,tr),
                query(i<<1|1,mid+1,r,tl,tr));
    }

    ll query(int l, int r) { return query(1,0,n-1,l,r); }
    void update(int tg, ll x) { update(1,0,n-1,x,tg); }

};

#ifdef ONPC
void
solve()
{
    int n, m;
    cin >> m >> n;
    vector<d> ns(m);
    set<int> tset;
    vector<int> val;
    map<int,int> comp;
    for (int i = 0; i < m; ++i) {
        cin >> ns[i].l >> ns[i].r >> ns[i].out >> ns[i].p;
        tset.insert(ns[i].out);
    }
    tset.insert(1);
    tset.insert(n);

    for (int u : tset)
        val.pb(u);

    for (int i = 0; i < sz(val); ++i) comp[val[i]]=i;

    SGT l(sz(val)+1);
    SGT r(sz(val)+1);
    l.update(comp[1],0);
    r.update(comp[n],0);

    ll ans = inf;
    for (int i = 0; i < m; ++i) {
        int lp, rp, tg;

        lp = comp[*(tset.lower_bound(ns[i].l))];
        rp = *(tset.lower_bound(ns[i].r));
        if (rp > ns[i].r)
            rp = *(--tset.lower_bound(ns[i].r));
        rp = comp[rp];
        tg = comp[*(tset.lower_bound(ns[i].out))];

        assert(lp <= rp);

        ll val1 = l.query(lp,rp);
        ll val2 = r.query(lp,rp);

        ans = min(ans,val1+val2+ns[i].p);

        l.update(tg,val1+ns[i].p);
        r.update(tg,val2+ns[i].p);
    }

    if (ans >= inf)
        cout << "-1\n";
    else
        cout << ans << endl;
}

int32_t
main(int argc, char **argv)
{
    if (argc >= 2) {
        freopen(argv[1], "r", stdin);
    } else
        ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    /* cin >> t; */
    while(t--)
        solve();
}
#endif

Compilation message

pinball.cpp: In function 'int32_t main(int, char**)':
pinball.cpp:132:7: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  132 |     } else
      |       ^~~~
pinball.cpp:133:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  133 |         ios_base::sync_with_stdio(0);cin.tie(0);
      |                                      ^~~
pinball.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         freopen(argv[1], "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 22 ms 2004 KB Output is correct
26 Correct 67 ms 5048 KB Output is correct
27 Correct 258 ms 11548 KB Output is correct
28 Correct 140 ms 6644 KB Output is correct
29 Correct 152 ms 9352 KB Output is correct
30 Correct 225 ms 7996 KB Output is correct
31 Correct 419 ms 17668 KB Output is correct
32 Correct 339 ms 15396 KB Output is correct
33 Correct 39 ms 4564 KB Output is correct
34 Correct 192 ms 11504 KB Output is correct
35 Correct 219 ms 22556 KB Output is correct
36 Correct 469 ms 22572 KB Output is correct
37 Correct 364 ms 22592 KB Output is correct
38 Correct 336 ms 22540 KB Output is correct