답안 #1026103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026103 2024-07-17T14:59:12 Z hotboy2703 Sky Walking (IOI19_walk) C++17
33 / 100
147 ms 21184 KB
#include "walk.h"
#include<bits/stdc++.h>
    using namespace std;
    using ll = long long;
    #define pll pair <ll,ll>
    #define fi first
    #define se second
    #define MP make_pair
    #define sz(a) (ll((a).size()))
    #define BIT(mask,i) (((mask) >> (i))&1)
    #define MASK(i) (1LL << (i))
//namespace fail{

    struct walk{
        ll l,r,y;
    };
    vector <walk> all;
    const ll MAXN = 1e5 + 100;
    const ll INF = 1e18;
    ll dp[MAXN];
    long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int S, int G){
        ll m = sz(l);
        ll n = sz(x);
        for (ll i = 0;i < m;i ++){
            all.push_back({l[i],r[i],y[i]});
        }
    //    sort(all.begin(),all.end(),[](walk a1,walk a2){return a1.y>a2.y;});
    //    vector <ll> order;
    //    order.resize(n);
    //    iota(order.begin(),order.end(),0);
    //    sort(order.begin(),order.end(),[&](ll x,ll y){return h[x] > h[y];});
    ////    cout<<"OK"<<endl;
    //    {
    //        set <ll> s;
    //        s.insert(-1);
    //        s.insert(n);
    //        for (ll i = 0,ptr = 0;i < n;i ++){
    //            while (ptr < sz(order) && h[order[ptr]] >= all[i].y){
    //                s.insert(order[ptr]);
    //                ptr++;
    //            }
    //            all[i].l = *lower_bound(s.begin(),s.end(),all[i].l);
    //            all[i].r = *prev(upper_bound(s.begin(),s.end(),all[i].r));
    //        }
    //    }
        sort(all.begin(),all.end(),[](walk a1,walk a2){return a1.r<a2.r;});
        vector <pll> event;
        for (ll i = 0;i < m;i ++){
            if (all[i].l > all[i].r)continue;
            event.push_back(MP(all[i].l,i));
            event.push_back(MP(all[i].r,i));
        }
    //    cout<<"OK"<<endl;
        sort(event.begin(),event.end());
        memset(dp,0x3f,sizeof dp);
        set <pll> s;
    //    return -1;
        ll res = INF;
        for (ll i = 0,ptr = 0;i < m;i ++){
    //        cout<<i<<endl;
            if (all[i].l > all[i].r)continue;
            while (ptr < sz(event) && event[ptr].fi <= all[i].r){
                pll x;
                x.se = event[ptr].se;
                x.fi = all[x.se].y;
                if (s.find(x) != s.end())s.erase(x);
                else s.insert(x);
    //    cout<<ptr<<endl;
                ptr++;
            }

            if (all[i].l == 0)dp[i] = all[i].y;
            auto tmp = s.lower_bound(MP(all[i].y,i));
            if (tmp != s.begin())dp[(*prev(tmp)).se] = min(dp[(*prev(tmp)).se],dp[i] + abs((*prev(tmp)).fi - all[i].y));
    //        assert(tmp != s.end());
            if (tmp != s.end())dp[(*tmp).se] = min(dp[(*tmp).se],dp[i] + abs((*tmp).fi - all[i].y));
            if (all[i].r == n - 1)res = min(res,dp[i] + x[n-1]-x[0]+all[i].y);
//            cout<<i<<' '<<all[i].l<<' '<<all[i].r<<' '<<dp[i]<<endl;
        }
        if (res==INF)res=-1;
        return res;
    }

//}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6012 KB Output is correct
2 Correct 91 ms 12936 KB Output is correct
3 Correct 95 ms 13472 KB Output is correct
4 Correct 105 ms 16844 KB Output is correct
5 Correct 135 ms 20932 KB Output is correct
6 Correct 129 ms 17368 KB Output is correct
7 Correct 46 ms 10696 KB Output is correct
8 Correct 51 ms 16840 KB Output is correct
9 Correct 118 ms 17604 KB Output is correct
10 Correct 84 ms 16944 KB Output is correct
11 Correct 12 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6012 KB Output is correct
2 Correct 91 ms 12936 KB Output is correct
3 Correct 95 ms 13472 KB Output is correct
4 Correct 105 ms 16844 KB Output is correct
5 Correct 135 ms 20932 KB Output is correct
6 Correct 129 ms 17368 KB Output is correct
7 Correct 46 ms 10696 KB Output is correct
8 Correct 51 ms 16840 KB Output is correct
9 Correct 118 ms 17604 KB Output is correct
10 Correct 84 ms 16944 KB Output is correct
11 Correct 12 ms 2652 KB Output is correct
12 Correct 95 ms 13512 KB Output is correct
13 Correct 106 ms 16824 KB Output is correct
14 Correct 143 ms 21184 KB Output is correct
15 Correct 87 ms 16836 KB Output is correct
16 Correct 85 ms 16712 KB Output is correct
17 Correct 85 ms 16840 KB Output is correct
18 Correct 87 ms 16664 KB Output is correct
19 Correct 84 ms 16840 KB Output is correct
20 Correct 56 ms 10708 KB Output is correct
21 Correct 16 ms 4700 KB Output is correct
22 Correct 79 ms 15816 KB Output is correct
23 Correct 69 ms 16072 KB Output is correct
24 Correct 70 ms 16072 KB Output is correct
25 Correct 62 ms 15800 KB Output is correct
26 Correct 72 ms 16472 KB Output is correct
27 Correct 147 ms 19908 KB Output is correct
28 Correct 86 ms 16840 KB Output is correct
29 Correct 129 ms 17232 KB Output is correct
30 Correct 48 ms 10708 KB Output is correct
31 Correct 123 ms 17600 KB Output is correct
32 Correct 65 ms 15728 KB Output is correct
33 Correct 61 ms 16072 KB Output is correct
34 Correct 74 ms 15812 KB Output is correct
35 Correct 65 ms 15816 KB Output is correct
36 Correct 50 ms 15560 KB Output is correct
37 Correct 45 ms 15208 KB Output is correct
38 Correct 48 ms 15824 KB Output is correct
39 Correct 102 ms 16564 KB Output is correct
40 Correct 53 ms 15644 KB Output is correct
41 Correct 48 ms 15048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -