답안 #262123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262123 2020-08-12T11:28:06 Z Kastanda 치료 계획 (JOI20_treatment) C++11
100 / 100
1287 ms 101744 KB
// M
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
int n, m, T[N], L[N], R[N], C[N], P[N], rev[N];
ll D[N];
vector < int > vec;
priority_queue < pair < ll , int > > Pq;
set < pair < int , int > > ST[2][N];
inline void Add(int w, int i, pair < int , int > val)
{
        for (; i < N; i += i & - i)
                ST[w][i].insert(val);
}
inline void Get(int w, int i, int ri)
{
        for (; i; i -= i & - i)
                while (ST[w][i].size() && ST[w][i].begin()->first <= ri)
                {
                        if (D[ST[w][i].begin()->second] == -1)
                                vec.push_back(ST[w][i].begin()->second);
                        ST[w][i].erase(ST[w][i].begin());
                }
}
int main()
{
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= m; i ++)
                scanf("%d%d%d%d", &T[i], &L[i], &R[i], &C[i]), R[i] ++;
        iota(P + 1, P + m + 1, 1);
        sort(P + 1, P + m + 1, [&](int i, int j){return T[i] < T[j];});
        for (int i = 1; i <= m; i ++)
                rev[P[i]] = i;

        for (int i = m; i; i --)
                Add(0, m - i + 1, make_pair(L[P[i]] + T[P[i]], P[i]));
        for (int i = 1; i <= m; i ++)
                Add(1, i, make_pair(L[P[i]] - T[P[i]], P[i]));

        memset(D, -1, sizeof(D));
        for (int i = 1; i <= m; i ++)
                if (L[i] == 1)
                        D[i] = C[i], Pq.push({-D[i], i});

        while (Pq.size())
        {
                ll d = - Pq.top().first;
                int v = Pq.top().second;
                Pq.pop();
                if (R[v] == n + 1)
                        return !printf("%lld\n", d);

                vec.clear();
                Get(0, m - rev[v], R[v] + T[v]);
                Get(1, rev[v] - 1, R[v] - T[v]);

                for (int u : vec)
                        if (D[u] == -1)
                                D[u] = D[v] + C[u], Pq.push({-D[u], u});
        }
        return !printf("-1\n");
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         scanf("%d%d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:30:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |                 scanf("%d%d%d%d", &T[i], &L[i], &R[i], &C[i]), R[i] ++;
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1071 ms 98544 KB Output is correct
2 Correct 755 ms 98552 KB Output is correct
3 Correct 1070 ms 98752 KB Output is correct
4 Correct 920 ms 98812 KB Output is correct
5 Correct 600 ms 100596 KB Output is correct
6 Correct 694 ms 98636 KB Output is correct
7 Correct 525 ms 98424 KB Output is correct
8 Correct 569 ms 98516 KB Output is correct
9 Correct 425 ms 98460 KB Output is correct
10 Correct 488 ms 98424 KB Output is correct
11 Correct 559 ms 100976 KB Output is correct
12 Correct 752 ms 100968 KB Output is correct
13 Correct 1008 ms 100560 KB Output is correct
14 Correct 971 ms 100592 KB Output is correct
15 Correct 1287 ms 98512 KB Output is correct
16 Correct 1154 ms 98504 KB Output is correct
17 Correct 1072 ms 97784 KB Output is correct
18 Correct 592 ms 100164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10496 KB Output is correct
2 Correct 7 ms 10496 KB Output is correct
3 Correct 8 ms 10656 KB Output is correct
4 Correct 7 ms 10496 KB Output is correct
5 Correct 7 ms 10496 KB Output is correct
6 Correct 7 ms 10496 KB Output is correct
7 Correct 7 ms 10604 KB Output is correct
8 Correct 8 ms 10496 KB Output is correct
9 Correct 7 ms 10496 KB Output is correct
10 Correct 7 ms 10496 KB Output is correct
11 Correct 8 ms 10496 KB Output is correct
12 Correct 8 ms 10496 KB Output is correct
13 Correct 9 ms 10496 KB Output is correct
14 Correct 8 ms 10496 KB Output is correct
15 Correct 7 ms 10496 KB Output is correct
16 Correct 8 ms 10496 KB Output is correct
17 Correct 8 ms 10496 KB Output is correct
18 Correct 8 ms 10496 KB Output is correct
19 Correct 7 ms 10496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10496 KB Output is correct
2 Correct 7 ms 10496 KB Output is correct
3 Correct 8 ms 10656 KB Output is correct
4 Correct 7 ms 10496 KB Output is correct
5 Correct 7 ms 10496 KB Output is correct
6 Correct 7 ms 10496 KB Output is correct
7 Correct 7 ms 10604 KB Output is correct
8 Correct 8 ms 10496 KB Output is correct
9 Correct 7 ms 10496 KB Output is correct
10 Correct 7 ms 10496 KB Output is correct
11 Correct 8 ms 10496 KB Output is correct
12 Correct 8 ms 10496 KB Output is correct
13 Correct 9 ms 10496 KB Output is correct
14 Correct 8 ms 10496 KB Output is correct
15 Correct 7 ms 10496 KB Output is correct
16 Correct 8 ms 10496 KB Output is correct
17 Correct 8 ms 10496 KB Output is correct
18 Correct 8 ms 10496 KB Output is correct
19 Correct 7 ms 10496 KB Output is correct
20 Correct 35 ms 15992 KB Output is correct
21 Correct 33 ms 16000 KB Output is correct
22 Correct 31 ms 16000 KB Output is correct
23 Correct 30 ms 15992 KB Output is correct
24 Correct 34 ms 16120 KB Output is correct
25 Correct 44 ms 15992 KB Output is correct
26 Correct 42 ms 16068 KB Output is correct
27 Correct 41 ms 16028 KB Output is correct
28 Correct 39 ms 16180 KB Output is correct
29 Correct 36 ms 16000 KB Output is correct
30 Correct 32 ms 15992 KB Output is correct
31 Correct 35 ms 16052 KB Output is correct
32 Correct 39 ms 16120 KB Output is correct
33 Correct 34 ms 16128 KB Output is correct
34 Correct 36 ms 16040 KB Output is correct
35 Correct 34 ms 16128 KB Output is correct
36 Correct 34 ms 16120 KB Output is correct
37 Correct 35 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1071 ms 98544 KB Output is correct
2 Correct 755 ms 98552 KB Output is correct
3 Correct 1070 ms 98752 KB Output is correct
4 Correct 920 ms 98812 KB Output is correct
5 Correct 600 ms 100596 KB Output is correct
6 Correct 694 ms 98636 KB Output is correct
7 Correct 525 ms 98424 KB Output is correct
8 Correct 569 ms 98516 KB Output is correct
9 Correct 425 ms 98460 KB Output is correct
10 Correct 488 ms 98424 KB Output is correct
11 Correct 559 ms 100976 KB Output is correct
12 Correct 752 ms 100968 KB Output is correct
13 Correct 1008 ms 100560 KB Output is correct
14 Correct 971 ms 100592 KB Output is correct
15 Correct 1287 ms 98512 KB Output is correct
16 Correct 1154 ms 98504 KB Output is correct
17 Correct 1072 ms 97784 KB Output is correct
18 Correct 592 ms 100164 KB Output is correct
19 Correct 7 ms 10496 KB Output is correct
20 Correct 7 ms 10496 KB Output is correct
21 Correct 8 ms 10656 KB Output is correct
22 Correct 7 ms 10496 KB Output is correct
23 Correct 7 ms 10496 KB Output is correct
24 Correct 7 ms 10496 KB Output is correct
25 Correct 7 ms 10604 KB Output is correct
26 Correct 8 ms 10496 KB Output is correct
27 Correct 7 ms 10496 KB Output is correct
28 Correct 7 ms 10496 KB Output is correct
29 Correct 8 ms 10496 KB Output is correct
30 Correct 8 ms 10496 KB Output is correct
31 Correct 9 ms 10496 KB Output is correct
32 Correct 8 ms 10496 KB Output is correct
33 Correct 7 ms 10496 KB Output is correct
34 Correct 8 ms 10496 KB Output is correct
35 Correct 8 ms 10496 KB Output is correct
36 Correct 8 ms 10496 KB Output is correct
37 Correct 7 ms 10496 KB Output is correct
38 Correct 35 ms 15992 KB Output is correct
39 Correct 33 ms 16000 KB Output is correct
40 Correct 31 ms 16000 KB Output is correct
41 Correct 30 ms 15992 KB Output is correct
42 Correct 34 ms 16120 KB Output is correct
43 Correct 44 ms 15992 KB Output is correct
44 Correct 42 ms 16068 KB Output is correct
45 Correct 41 ms 16028 KB Output is correct
46 Correct 39 ms 16180 KB Output is correct
47 Correct 36 ms 16000 KB Output is correct
48 Correct 32 ms 15992 KB Output is correct
49 Correct 35 ms 16052 KB Output is correct
50 Correct 39 ms 16120 KB Output is correct
51 Correct 34 ms 16128 KB Output is correct
52 Correct 36 ms 16040 KB Output is correct
53 Correct 34 ms 16128 KB Output is correct
54 Correct 34 ms 16120 KB Output is correct
55 Correct 35 ms 16000 KB Output is correct
56 Correct 721 ms 99140 KB Output is correct
57 Correct 651 ms 98932 KB Output is correct
58 Correct 575 ms 97656 KB Output is correct
59 Correct 736 ms 98056 KB Output is correct
60 Correct 822 ms 98680 KB Output is correct
61 Correct 732 ms 97764 KB Output is correct
62 Correct 752 ms 99060 KB Output is correct
63 Correct 499 ms 98552 KB Output is correct
64 Correct 422 ms 98552 KB Output is correct
65 Correct 1218 ms 98708 KB Output is correct
66 Correct 536 ms 98680 KB Output is correct
67 Correct 952 ms 99320 KB Output is correct
68 Correct 1088 ms 99144 KB Output is correct
69 Correct 766 ms 99240 KB Output is correct
70 Correct 995 ms 99420 KB Output is correct
71 Correct 889 ms 99192 KB Output is correct
72 Correct 740 ms 99192 KB Output is correct
73 Correct 979 ms 99344 KB Output is correct
74 Correct 513 ms 99224 KB Output is correct
75 Correct 489 ms 99320 KB Output is correct
76 Correct 653 ms 101484 KB Output is correct
77 Correct 662 ms 100564 KB Output is correct
78 Correct 867 ms 100940 KB Output is correct
79 Correct 1020 ms 99316 KB Output is correct
80 Correct 974 ms 98936 KB Output is correct
81 Correct 561 ms 99192 KB Output is correct
82 Correct 977 ms 98240 KB Output is correct
83 Correct 994 ms 98452 KB Output is correct
84 Correct 1134 ms 98556 KB Output is correct
85 Correct 765 ms 99320 KB Output is correct
86 Correct 837 ms 99332 KB Output is correct
87 Correct 795 ms 99320 KB Output is correct
88 Correct 669 ms 99192 KB Output is correct
89 Correct 773 ms 99320 KB Output is correct
90 Correct 590 ms 101744 KB Output is correct
91 Correct 559 ms 99296 KB Output is correct
92 Correct 843 ms 99192 KB Output is correct
93 Correct 933 ms 99192 KB Output is correct
94 Correct 919 ms 99480 KB Output is correct
95 Correct 874 ms 99192 KB Output is correct
96 Correct 640 ms 100464 KB Output is correct
97 Correct 666 ms 101452 KB Output is correct
98 Correct 648 ms 101372 KB Output is correct
99 Correct 667 ms 101440 KB Output is correct
100 Correct 659 ms 101736 KB Output is correct
101 Correct 751 ms 101424 KB Output is correct
102 Correct 578 ms 101724 KB Output is correct
103 Correct 700 ms 99580 KB Output is correct