답안 #241298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
241298 2020-06-23T18:05:31 Z Mercenary 치료 계획 (JOI20_treatment) C++14
100 / 100
338 ms 33168 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 10;

int n , m;

struct project{
    int t , l , r , c , id;
    int t1;
}a[maxn];
ll dis[maxn];
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;

template<char T>
struct BIT{
    vector<ii> val[maxn];
    void add(int x , ii y){
        if(T){
            for( ; x > 0 ; x &= x - 1)
                val[x].pb(y);
        }else{
             for( ; x < maxn ; x += x & -x)
                val[x].pb(y);
        }
    }
    void update_dis(int u , ll d){
        d += a[u].c;
//        cout << u << " " <<  d << endl;
        if(dis[u] > d){
            dis[u] = d;
            pq.push(mp(d , u));
        }
    }
    void del(int x , int y , ll dis){
        if(T){
            for( ; x < maxn ; x += x & -x){
                while(val[x].size() > 0 && val[x].back().first <= y){
                    update_dis(val[x].back().second , dis);
                    val[x].pop_back();
                }
            }
        }else{
             for( ; x > 0 ; x &= x - 1){
                while(val[x].size() > 0 && val[x].back().first <= y){
                    update_dis(val[x].back().second , dis);
                    val[x].pop_back();
                }
             }
        }
    }
};

BIT<0> s;
BIT<1> s1;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    fill_n(dis,maxn,1e18);
    cin >> n >> m;
    vector<int> val;
    for(int i = 0 ; i < m ; ++i){
        cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
        a[i].id = i;
        a[i].l--;
        val.pb(a[i].t);
    }
    sort(val.begin(),val.end());
    for(int i = 0 ; i < m ; ++i){
        a[i].t1 = lower_bound(val.begin(),val.end(),a[i].t) - val.begin() + 1;
    }
    sort(a , a + m , [&](const project x , const project y){
        return x.t + x.l > y.t + y.l;
         });
    for(int i = 0 ; i < m ; ++i){
        s1.add(a[i].t1,mp(a[i].t + a[i].l , a[i].id));
    }
    sort(a , a + m , [&](const project x , const project y){
        return x.l - x.t > y.l - y.t;
         });
    for(int i = 0 ; i < m ; ++i){
        s.add(a[i].t1,mp(a[i].l - a[i].t , a[i].id));
    }
    sort(a , a + m , [&](const project x , const project y){
        return x.id < y.id;
         });
    ll res = 1e18;
    for(int i = 0 ; i < m ; ++i){
        if(a[i].l == 0){
            dis[i] = a[i].c;
            pq.push(mp(dis[i] , i));
        }
    }
    while(pq.size()){
        auto u = pq.top();pq.pop();
        if(u.first != dis[u.second])continue;
        int i = u.second;
//        cout << i << endl;
        s1.del(a[i].t1 , a[i].r + a[i].t , u.first);
        s.del(a[i].t1 , a[i].r - a[i].t , u.first);
    }
    for(int i = 0 ; i < m ; ++i){
        if(a[i].r == n){
//            cout << i << " " << dis[i] << endl;
            res = min(res , dis[i]);
        }
    }
    if(res == 1e18)cout << -1;
    else cout << res;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:75:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
treatment.cpp:76:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 30064 KB Output is correct
2 Correct 109 ms 30064 KB Output is correct
3 Correct 112 ms 29804 KB Output is correct
4 Correct 107 ms 29144 KB Output is correct
5 Correct 118 ms 32124 KB Output is correct
6 Correct 115 ms 30040 KB Output is correct
7 Correct 104 ms 29936 KB Output is correct
8 Correct 96 ms 29936 KB Output is correct
9 Correct 98 ms 29936 KB Output is correct
10 Correct 98 ms 29936 KB Output is correct
11 Correct 126 ms 32112 KB Output is correct
12 Correct 118 ms 32108 KB Output is correct
13 Correct 121 ms 32112 KB Output is correct
14 Correct 125 ms 32344 KB Output is correct
15 Correct 115 ms 29936 KB Output is correct
16 Correct 116 ms 30196 KB Output is correct
17 Correct 103 ms 29168 KB Output is correct
18 Correct 119 ms 31500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5760 KB Output is correct
2 Correct 8 ms 5888 KB Output is correct
3 Correct 8 ms 5888 KB Output is correct
4 Correct 8 ms 5760 KB Output is correct
5 Correct 8 ms 5888 KB Output is correct
6 Correct 8 ms 5760 KB Output is correct
7 Correct 8 ms 5888 KB Output is correct
8 Correct 8 ms 5760 KB Output is correct
9 Correct 8 ms 5888 KB Output is correct
10 Correct 8 ms 5760 KB Output is correct
11 Correct 8 ms 5760 KB Output is correct
12 Correct 7 ms 5760 KB Output is correct
13 Correct 8 ms 5888 KB Output is correct
14 Correct 8 ms 5888 KB Output is correct
15 Correct 8 ms 5760 KB Output is correct
16 Correct 8 ms 5760 KB Output is correct
17 Correct 8 ms 5760 KB Output is correct
18 Correct 8 ms 5760 KB Output is correct
19 Correct 8 ms 5760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5760 KB Output is correct
2 Correct 8 ms 5888 KB Output is correct
3 Correct 8 ms 5888 KB Output is correct
4 Correct 8 ms 5760 KB Output is correct
5 Correct 8 ms 5888 KB Output is correct
6 Correct 8 ms 5760 KB Output is correct
7 Correct 8 ms 5888 KB Output is correct
8 Correct 8 ms 5760 KB Output is correct
9 Correct 8 ms 5888 KB Output is correct
10 Correct 8 ms 5760 KB Output is correct
11 Correct 8 ms 5760 KB Output is correct
12 Correct 7 ms 5760 KB Output is correct
13 Correct 8 ms 5888 KB Output is correct
14 Correct 8 ms 5888 KB Output is correct
15 Correct 8 ms 5760 KB Output is correct
16 Correct 8 ms 5760 KB Output is correct
17 Correct 8 ms 5760 KB Output is correct
18 Correct 8 ms 5760 KB Output is correct
19 Correct 8 ms 5760 KB Output is correct
20 Correct 15 ms 7040 KB Output is correct
21 Correct 15 ms 7040 KB Output is correct
22 Correct 15 ms 7168 KB Output is correct
23 Correct 14 ms 7040 KB Output is correct
24 Correct 17 ms 7168 KB Output is correct
25 Correct 17 ms 7168 KB Output is correct
26 Correct 16 ms 7040 KB Output is correct
27 Correct 15 ms 7040 KB Output is correct
28 Correct 16 ms 7168 KB Output is correct
29 Correct 16 ms 7040 KB Output is correct
30 Correct 14 ms 7040 KB Output is correct
31 Correct 14 ms 7168 KB Output is correct
32 Correct 16 ms 7296 KB Output is correct
33 Correct 18 ms 7296 KB Output is correct
34 Correct 16 ms 7168 KB Output is correct
35 Correct 16 ms 7296 KB Output is correct
36 Correct 15 ms 7296 KB Output is correct
37 Correct 16 ms 7040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 30064 KB Output is correct
2 Correct 109 ms 30064 KB Output is correct
3 Correct 112 ms 29804 KB Output is correct
4 Correct 107 ms 29144 KB Output is correct
5 Correct 118 ms 32124 KB Output is correct
6 Correct 115 ms 30040 KB Output is correct
7 Correct 104 ms 29936 KB Output is correct
8 Correct 96 ms 29936 KB Output is correct
9 Correct 98 ms 29936 KB Output is correct
10 Correct 98 ms 29936 KB Output is correct
11 Correct 126 ms 32112 KB Output is correct
12 Correct 118 ms 32108 KB Output is correct
13 Correct 121 ms 32112 KB Output is correct
14 Correct 125 ms 32344 KB Output is correct
15 Correct 115 ms 29936 KB Output is correct
16 Correct 116 ms 30196 KB Output is correct
17 Correct 103 ms 29168 KB Output is correct
18 Correct 119 ms 31500 KB Output is correct
19 Correct 8 ms 5760 KB Output is correct
20 Correct 8 ms 5888 KB Output is correct
21 Correct 8 ms 5888 KB Output is correct
22 Correct 8 ms 5760 KB Output is correct
23 Correct 8 ms 5888 KB Output is correct
24 Correct 8 ms 5760 KB Output is correct
25 Correct 8 ms 5888 KB Output is correct
26 Correct 8 ms 5760 KB Output is correct
27 Correct 8 ms 5888 KB Output is correct
28 Correct 8 ms 5760 KB Output is correct
29 Correct 8 ms 5760 KB Output is correct
30 Correct 7 ms 5760 KB Output is correct
31 Correct 8 ms 5888 KB Output is correct
32 Correct 8 ms 5888 KB Output is correct
33 Correct 8 ms 5760 KB Output is correct
34 Correct 8 ms 5760 KB Output is correct
35 Correct 8 ms 5760 KB Output is correct
36 Correct 8 ms 5760 KB Output is correct
37 Correct 8 ms 5760 KB Output is correct
38 Correct 15 ms 7040 KB Output is correct
39 Correct 15 ms 7040 KB Output is correct
40 Correct 15 ms 7168 KB Output is correct
41 Correct 14 ms 7040 KB Output is correct
42 Correct 17 ms 7168 KB Output is correct
43 Correct 17 ms 7168 KB Output is correct
44 Correct 16 ms 7040 KB Output is correct
45 Correct 15 ms 7040 KB Output is correct
46 Correct 16 ms 7168 KB Output is correct
47 Correct 16 ms 7040 KB Output is correct
48 Correct 14 ms 7040 KB Output is correct
49 Correct 14 ms 7168 KB Output is correct
50 Correct 16 ms 7296 KB Output is correct
51 Correct 18 ms 7296 KB Output is correct
52 Correct 16 ms 7168 KB Output is correct
53 Correct 16 ms 7296 KB Output is correct
54 Correct 15 ms 7296 KB Output is correct
55 Correct 16 ms 7040 KB Output is correct
56 Correct 214 ms 29940 KB Output is correct
57 Correct 221 ms 30200 KB Output is correct
58 Correct 182 ms 28532 KB Output is correct
59 Correct 188 ms 28916 KB Output is correct
60 Correct 185 ms 29732 KB Output is correct
61 Correct 187 ms 28532 KB Output is correct
62 Correct 197 ms 29812 KB Output is correct
63 Correct 159 ms 29184 KB Output is correct
64 Correct 164 ms 28916 KB Output is correct
65 Correct 119 ms 30060 KB Output is correct
66 Correct 169 ms 29652 KB Output is correct
67 Correct 260 ms 29812 KB Output is correct
68 Correct 237 ms 29684 KB Output is correct
69 Correct 227 ms 30136 KB Output is correct
70 Correct 280 ms 29876 KB Output is correct
71 Correct 252 ms 29716 KB Output is correct
72 Correct 216 ms 29684 KB Output is correct
73 Correct 287 ms 29916 KB Output is correct
74 Correct 171 ms 29660 KB Output is correct
75 Correct 167 ms 29856 KB Output is correct
76 Correct 270 ms 33168 KB Output is correct
77 Correct 260 ms 31984 KB Output is correct
78 Correct 275 ms 33136 KB Output is correct
79 Correct 267 ms 29788 KB Output is correct
80 Correct 275 ms 31068 KB Output is correct
81 Correct 197 ms 29680 KB Output is correct
82 Correct 293 ms 30192 KB Output is correct
83 Correct 288 ms 29044 KB Output is correct
84 Correct 289 ms 28912 KB Output is correct
85 Correct 231 ms 29816 KB Output is correct
86 Correct 267 ms 29812 KB Output is correct
87 Correct 338 ms 29788 KB Output is correct
88 Correct 210 ms 29684 KB Output is correct
89 Correct 234 ms 29724 KB Output is correct
90 Correct 285 ms 31856 KB Output is correct
91 Correct 290 ms 30836 KB Output is correct
92 Correct 226 ms 29684 KB Output is correct
93 Correct 296 ms 29812 KB Output is correct
94 Correct 258 ms 30028 KB Output is correct
95 Correct 254 ms 29684 KB Output is correct
96 Correct 292 ms 31832 KB Output is correct
97 Correct 273 ms 31856 KB Output is correct
98 Correct 288 ms 31900 KB Output is correct
99 Correct 272 ms 31968 KB Output is correct
100 Correct 265 ms 31984 KB Output is correct
101 Correct 257 ms 31852 KB Output is correct
102 Correct 254 ms 31852 KB Output is correct
103 Correct 236 ms 30280 KB Output is correct