Submission #1094372

# Submission time Handle Problem Language Result Execution time Memory
1094372 2024-09-29T13:25:14 Z thangdz2k7 Treatment Project (JOI20_treatment) C++17
100 / 100
76 ms 10824 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using li = pair <ll, int>;
using vi = vector <int>;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const ll inf = 1e18;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

struct project{
    int t, l, r, c;

    bool operator < (project other){
        return l - t < other.l - other.t;
    }
} p[N];

int NN, m;
ll d[N], Min[4 * N];

void build(int s = 1, int l = 1, int r = m){
    if (l == r){
        Min[s] = p[l].l + p[l].t;
        return;
    }

    int mid = l + r >> 1;
    build(s << 1, l, mid); build(s << 1 | 1, mid + 1, r);
    Min[s] = min(Min[s << 1], Min[s << 1 | 1]);
}

priority_queue <li, vector <li>, greater <li>> qu;

void get(int u, int v, ll k, int s = 1, int l = 1, int r = m){
    if (p[l].l - p[l].t > u || Min[s] > v) return;
    if (l == r){
        if (d[l] == inf){
            d[l] = k + p[l].c;
            qu.push({d[l], l});
        }
        Min[s] = inf;
        return;
    }

    int mid = l + r >> 1;
    get(u, v, k, s << 1, l, mid); get(u, v, k, s << 1 | 1, mid + 1, r);
    Min[s] = min(Min[s << 1], Min[s << 1 | 1]);
}

void solve(){
    cin >> NN >> m;
    for (int i = 1; i <= m; ++ i){
        cin >> p[i].t >> p[i].l >> p[i].r >> p[i].c;
        d[i] = inf;
    }

    sort(p + 1, p + m + 1); build();
    for (int i = 1; i <= m; ++ i) if (p[i].l == 1){
        d[i] = p[i].c;
        qu.push({d[i], i});
    }

    while (qu.size()){
        auto [du, u] = qu.top(); qu.pop();
        get(p[u].r - p[u].t + 1, p[u].r + p[u].t + 1, du);
    }

    ll ans = inf;
    for (int i = 1; i <= m; ++ i) if (p[i].r == NN) minl(ans, d[i]);
    if (ans == inf) cout << -1;
    else cout << ans;
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

treatment.cpp:20:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
treatment.cpp:20:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
treatment.cpp:21:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   21 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
treatment.cpp:21:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   21 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
treatment.cpp: In function 'void build(int, int, int)':
treatment.cpp:40:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |     int mid = l + r >> 1;
      |               ~~^~~
treatment.cpp: In function 'void get(int, int, ll, int, int, int)':
treatment.cpp:58:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |     int mid = l + r >> 1;
      |               ~~^~~
treatment.cpp: In function 'int main()':
treatment.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
treatment.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 49 ms 8016 KB Output is correct
2 Correct 39 ms 8016 KB Output is correct
3 Correct 47 ms 7556 KB Output is correct
4 Correct 49 ms 7636 KB Output is correct
5 Correct 44 ms 9932 KB Output is correct
6 Correct 41 ms 8172 KB Output is correct
7 Correct 44 ms 7768 KB Output is correct
8 Correct 28 ms 7820 KB Output is correct
9 Correct 30 ms 7760 KB Output is correct
10 Correct 29 ms 7748 KB Output is correct
11 Correct 49 ms 10180 KB Output is correct
12 Correct 47 ms 10192 KB Output is correct
13 Correct 46 ms 9932 KB Output is correct
14 Correct 48 ms 10016 KB Output is correct
15 Correct 43 ms 7764 KB Output is correct
16 Correct 41 ms 7952 KB Output is correct
17 Correct 42 ms 7200 KB Output is correct
18 Correct 48 ms 9432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 2 ms 704 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 856 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 3 ms 856 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 4 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 5 ms 1000 KB Output is correct
33 Correct 2 ms 996 KB Output is correct
34 Correct 3 ms 860 KB Output is correct
35 Correct 3 ms 856 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 8016 KB Output is correct
2 Correct 39 ms 8016 KB Output is correct
3 Correct 47 ms 7556 KB Output is correct
4 Correct 49 ms 7636 KB Output is correct
5 Correct 44 ms 9932 KB Output is correct
6 Correct 41 ms 8172 KB Output is correct
7 Correct 44 ms 7768 KB Output is correct
8 Correct 28 ms 7820 KB Output is correct
9 Correct 30 ms 7760 KB Output is correct
10 Correct 29 ms 7748 KB Output is correct
11 Correct 49 ms 10180 KB Output is correct
12 Correct 47 ms 10192 KB Output is correct
13 Correct 46 ms 9932 KB Output is correct
14 Correct 48 ms 10016 KB Output is correct
15 Correct 43 ms 7764 KB Output is correct
16 Correct 41 ms 7952 KB Output is correct
17 Correct 42 ms 7200 KB Output is correct
18 Correct 48 ms 9432 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 3 ms 860 KB Output is correct
41 Correct 2 ms 704 KB Output is correct
42 Correct 3 ms 860 KB Output is correct
43 Correct 3 ms 856 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 3 ms 856 KB Output is correct
46 Correct 3 ms 856 KB Output is correct
47 Correct 4 ms 860 KB Output is correct
48 Correct 2 ms 860 KB Output is correct
49 Correct 2 ms 860 KB Output is correct
50 Correct 5 ms 1000 KB Output is correct
51 Correct 2 ms 996 KB Output is correct
52 Correct 3 ms 860 KB Output is correct
53 Correct 3 ms 856 KB Output is correct
54 Correct 3 ms 860 KB Output is correct
55 Correct 2 ms 860 KB Output is correct
56 Correct 47 ms 8400 KB Output is correct
57 Correct 53 ms 8412 KB Output is correct
58 Correct 52 ms 7152 KB Output is correct
59 Correct 55 ms 7504 KB Output is correct
60 Correct 52 ms 8248 KB Output is correct
61 Correct 55 ms 7000 KB Output is correct
62 Correct 55 ms 8468 KB Output is correct
63 Correct 50 ms 8032 KB Output is correct
64 Correct 55 ms 7960 KB Output is correct
65 Correct 50 ms 8168 KB Output is correct
66 Correct 48 ms 8016 KB Output is correct
67 Correct 62 ms 8788 KB Output is correct
68 Correct 65 ms 8532 KB Output is correct
69 Correct 60 ms 8532 KB Output is correct
70 Correct 76 ms 8916 KB Output is correct
71 Correct 61 ms 8528 KB Output is correct
72 Correct 53 ms 8528 KB Output is correct
73 Correct 61 ms 8788 KB Output is correct
74 Correct 33 ms 8692 KB Output is correct
75 Correct 34 ms 8532 KB Output is correct
76 Correct 49 ms 10512 KB Output is correct
77 Correct 62 ms 10824 KB Output is correct
78 Correct 49 ms 10448 KB Output is correct
79 Correct 66 ms 8528 KB Output is correct
80 Correct 46 ms 8488 KB Output is correct
81 Correct 34 ms 8524 KB Output is correct
82 Correct 47 ms 7764 KB Output is correct
83 Correct 46 ms 7764 KB Output is correct
84 Correct 63 ms 8180 KB Output is correct
85 Correct 53 ms 8716 KB Output is correct
86 Correct 47 ms 8532 KB Output is correct
87 Correct 56 ms 8504 KB Output is correct
88 Correct 51 ms 8528 KB Output is correct
89 Correct 50 ms 8540 KB Output is correct
90 Correct 55 ms 10704 KB Output is correct
91 Correct 58 ms 9940 KB Output is correct
92 Correct 51 ms 8528 KB Output is correct
93 Correct 64 ms 8528 KB Output is correct
94 Correct 48 ms 8784 KB Output is correct
95 Correct 59 ms 8528 KB Output is correct
96 Correct 54 ms 10672 KB Output is correct
97 Correct 53 ms 10704 KB Output is correct
98 Correct 53 ms 10704 KB Output is correct
99 Correct 54 ms 10808 KB Output is correct
100 Correct 51 ms 10700 KB Output is correct
101 Correct 53 ms 10704 KB Output is correct
102 Correct 50 ms 10700 KB Output is correct
103 Correct 43 ms 9044 KB Output is correct