답안 #219395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219395 2020-04-05T08:39:31 Z ho94949 치료 계획 (JOI20_treatment) C++17
100 / 100
1666 ms 123024 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 262144;
int N, M;
int T[MAXM], L[MAXM], R[MAXM], C[MAXM];
int XL[MAXM], YL[MAXM], XR[MAXM], YR[MAXM];
bool vis[MAXM];

set<pair<int, int> > idx[2*MAXM];
bool in[MAXM];
void pushc(int x, int y, int i)
{
    //printf("PUSH %d %d %d\n", x, y, i);
    x += MAXM;
    while(x)
    {
        idx[x].emplace(y, i);
        x /= 2;
    }
    in[i] = true;
}
vector<int> popc(int x, int y)
{
    vector<int> ret;
    int f = MAXM, t = x+MAXM;
    while(f<=t && t)
    {
        if(t%2==0 || f==t)
        {
            auto it = idx[t].begin();
            while(it != idx[t].end())
            {
                auto [val, iv] = *it;
                if(val>y) break;
                if(in[iv]) ret.push_back(iv), in[iv] = false;
                auto pit = it; ++it; idx[t].erase(pit);
            }
            --t;
        }
        f/=2; t/=2;
    }
    /*printf("POP %d %d\n", x, y);
    for(auto q: ret) printf("%d ", q);
    puts("");*/
    return ret;
}

int main()
{
    scanf("%d%d", &N, &M);
    vector<int> x, y;
    for(int i=0; i<M; ++i)
    {
        scanf("%d%d%d%d", T+i, L+i, R+i, C+i);
        --L[i]; //L[i] = 0, R[i] = N covers whole
        XL[i] = L[i]-T[i], YL[i] = L[i]+T[i];
        XR[i] = R[i]-T[i], YR[i] = R[i]+T[i];
        x.push_back(XL[i]); x.push_back(XR[i]);
        y.push_back(YL[i]); y.push_back(YR[i]);
    }
    sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
    sort(y.begin(), y.end()); y.erase(unique(y.begin(), y.end()), y.end());
    for(int i=0; i<M; ++i)
    {
        XL[i] = lower_bound(x.begin(), x.end(), XL[i]) - x.begin();
        XR[i] = lower_bound(x.begin(), x.end(), XR[i]) - x.begin();
        YL[i] = lower_bound(y.begin(), y.end(), YL[i]) - y.begin();
        YR[i] = lower_bound(y.begin(), y.end(), YR[i]) - y.begin();
    }
    using pli = pair<long long, int>;
    priority_queue<pli, vector<pli>, greater<pli>> Q;
    for(int i=0; i<M; ++i)
        if(L[i] == 0)
            vis[i] = true, Q.emplace((long long)C[i], i);
        else
            pushc(XL[i], YL[i], i);
    while(!Q.empty())
    {
        auto [cost, idx] = Q.top(); Q.pop();
        if(R[idx] == N) return printf("%lld\n", cost), 0;

        vector<int> idxs = popc(XR[idx], YR[idx]);
        for(auto i: idxs)
        {
            vis[i] = true;
            Q.emplace(cost+C[i], i);
        }
    }
    puts("-1");
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", T+i, L+i, R+i, C+i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 997 ms 119140 KB Output is correct
2 Correct 982 ms 119136 KB Output is correct
3 Correct 706 ms 98204 KB Output is correct
4 Correct 698 ms 97584 KB Output is correct
5 Correct 681 ms 120560 KB Output is correct
6 Correct 739 ms 119520 KB Output is correct
7 Correct 624 ms 119140 KB Output is correct
8 Correct 626 ms 118240 KB Output is correct
9 Correct 710 ms 119136 KB Output is correct
10 Correct 587 ms 119264 KB Output is correct
11 Correct 1004 ms 122788 KB Output is correct
12 Correct 1012 ms 121584 KB Output is correct
13 Correct 1049 ms 121440 KB Output is correct
14 Correct 1048 ms 121320 KB Output is correct
15 Correct 1039 ms 119136 KB Output is correct
16 Correct 1039 ms 119264 KB Output is correct
17 Correct 1039 ms 119268 KB Output is correct
18 Correct 993 ms 122848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 24960 KB Output is correct
2 Correct 18 ms 24960 KB Output is correct
3 Correct 18 ms 24960 KB Output is correct
4 Correct 18 ms 24960 KB Output is correct
5 Correct 19 ms 25216 KB Output is correct
6 Correct 18 ms 24960 KB Output is correct
7 Correct 18 ms 25088 KB Output is correct
8 Correct 18 ms 24960 KB Output is correct
9 Correct 17 ms 24960 KB Output is correct
10 Correct 18 ms 24960 KB Output is correct
11 Correct 18 ms 25088 KB Output is correct
12 Correct 18 ms 25088 KB Output is correct
13 Correct 17 ms 25088 KB Output is correct
14 Correct 26 ms 25088 KB Output is correct
15 Correct 17 ms 24960 KB Output is correct
16 Correct 18 ms 24960 KB Output is correct
17 Correct 18 ms 24960 KB Output is correct
18 Correct 18 ms 24960 KB Output is correct
19 Correct 17 ms 24960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 24960 KB Output is correct
2 Correct 18 ms 24960 KB Output is correct
3 Correct 18 ms 24960 KB Output is correct
4 Correct 18 ms 24960 KB Output is correct
5 Correct 19 ms 25216 KB Output is correct
6 Correct 18 ms 24960 KB Output is correct
7 Correct 18 ms 25088 KB Output is correct
8 Correct 18 ms 24960 KB Output is correct
9 Correct 17 ms 24960 KB Output is correct
10 Correct 18 ms 24960 KB Output is correct
11 Correct 18 ms 25088 KB Output is correct
12 Correct 18 ms 25088 KB Output is correct
13 Correct 17 ms 25088 KB Output is correct
14 Correct 26 ms 25088 KB Output is correct
15 Correct 17 ms 24960 KB Output is correct
16 Correct 18 ms 24960 KB Output is correct
17 Correct 18 ms 24960 KB Output is correct
18 Correct 18 ms 24960 KB Output is correct
19 Correct 17 ms 24960 KB Output is correct
20 Correct 37 ms 28672 KB Output is correct
21 Correct 39 ms 28672 KB Output is correct
22 Correct 44 ms 29688 KB Output is correct
23 Correct 44 ms 29696 KB Output is correct
24 Correct 39 ms 29048 KB Output is correct
25 Correct 44 ms 29688 KB Output is correct
26 Correct 42 ms 29688 KB Output is correct
27 Correct 40 ms 29688 KB Output is correct
28 Correct 40 ms 29048 KB Output is correct
29 Correct 43 ms 29688 KB Output is correct
30 Correct 38 ms 29688 KB Output is correct
31 Correct 36 ms 29696 KB Output is correct
32 Correct 45 ms 29816 KB Output is correct
33 Correct 42 ms 29816 KB Output is correct
34 Correct 46 ms 29816 KB Output is correct
35 Correct 43 ms 29816 KB Output is correct
36 Correct 41 ms 29952 KB Output is correct
37 Correct 44 ms 29696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 997 ms 119140 KB Output is correct
2 Correct 982 ms 119136 KB Output is correct
3 Correct 706 ms 98204 KB Output is correct
4 Correct 698 ms 97584 KB Output is correct
5 Correct 681 ms 120560 KB Output is correct
6 Correct 739 ms 119520 KB Output is correct
7 Correct 624 ms 119140 KB Output is correct
8 Correct 626 ms 118240 KB Output is correct
9 Correct 710 ms 119136 KB Output is correct
10 Correct 587 ms 119264 KB Output is correct
11 Correct 1004 ms 122788 KB Output is correct
12 Correct 1012 ms 121584 KB Output is correct
13 Correct 1049 ms 121440 KB Output is correct
14 Correct 1048 ms 121320 KB Output is correct
15 Correct 1039 ms 119136 KB Output is correct
16 Correct 1039 ms 119264 KB Output is correct
17 Correct 1039 ms 119268 KB Output is correct
18 Correct 993 ms 122848 KB Output is correct
19 Correct 18 ms 24960 KB Output is correct
20 Correct 18 ms 24960 KB Output is correct
21 Correct 18 ms 24960 KB Output is correct
22 Correct 18 ms 24960 KB Output is correct
23 Correct 19 ms 25216 KB Output is correct
24 Correct 18 ms 24960 KB Output is correct
25 Correct 18 ms 25088 KB Output is correct
26 Correct 18 ms 24960 KB Output is correct
27 Correct 17 ms 24960 KB Output is correct
28 Correct 18 ms 24960 KB Output is correct
29 Correct 18 ms 25088 KB Output is correct
30 Correct 18 ms 25088 KB Output is correct
31 Correct 17 ms 25088 KB Output is correct
32 Correct 26 ms 25088 KB Output is correct
33 Correct 17 ms 24960 KB Output is correct
34 Correct 18 ms 24960 KB Output is correct
35 Correct 18 ms 24960 KB Output is correct
36 Correct 18 ms 24960 KB Output is correct
37 Correct 17 ms 24960 KB Output is correct
38 Correct 37 ms 28672 KB Output is correct
39 Correct 39 ms 28672 KB Output is correct
40 Correct 44 ms 29688 KB Output is correct
41 Correct 44 ms 29696 KB Output is correct
42 Correct 39 ms 29048 KB Output is correct
43 Correct 44 ms 29688 KB Output is correct
44 Correct 42 ms 29688 KB Output is correct
45 Correct 40 ms 29688 KB Output is correct
46 Correct 40 ms 29048 KB Output is correct
47 Correct 43 ms 29688 KB Output is correct
48 Correct 38 ms 29688 KB Output is correct
49 Correct 36 ms 29696 KB Output is correct
50 Correct 45 ms 29816 KB Output is correct
51 Correct 42 ms 29816 KB Output is correct
52 Correct 46 ms 29816 KB Output is correct
53 Correct 43 ms 29816 KB Output is correct
54 Correct 41 ms 29952 KB Output is correct
55 Correct 44 ms 29696 KB Output is correct
56 Correct 778 ms 98276 KB Output is correct
57 Correct 899 ms 98404 KB Output is correct
58 Correct 1028 ms 118888 KB Output is correct
59 Correct 1014 ms 118880 KB Output is correct
60 Correct 1224 ms 119196 KB Output is correct
61 Correct 1020 ms 118756 KB Output is correct
62 Correct 774 ms 98144 KB Output is correct
63 Correct 1027 ms 119136 KB Output is correct
64 Correct 1016 ms 119140 KB Output is correct
65 Correct 1034 ms 119268 KB Output is correct
66 Correct 1184 ms 119176 KB Output is correct
67 Correct 1314 ms 118496 KB Output is correct
68 Correct 1045 ms 119136 KB Output is correct
69 Correct 755 ms 119192 KB Output is correct
70 Correct 1323 ms 118724 KB Output is correct
71 Correct 1029 ms 119140 KB Output is correct
72 Correct 747 ms 119192 KB Output is correct
73 Correct 1363 ms 118748 KB Output is correct
74 Correct 892 ms 119136 KB Output is correct
75 Correct 643 ms 119008 KB Output is correct
76 Correct 1050 ms 122524 KB Output is correct
77 Correct 1478 ms 121000 KB Output is correct
78 Correct 1094 ms 121420 KB Output is correct
79 Correct 1666 ms 119292 KB Output is correct
80 Correct 1119 ms 119268 KB Output is correct
81 Correct 1494 ms 119128 KB Output is correct
82 Correct 1109 ms 119396 KB Output is correct
83 Correct 1345 ms 119240 KB Output is correct
84 Correct 1618 ms 119100 KB Output is correct
85 Correct 1483 ms 119432 KB Output is correct
86 Correct 1442 ms 119264 KB Output is correct
87 Correct 1480 ms 119212 KB Output is correct
88 Correct 1118 ms 119392 KB Output is correct
89 Correct 1429 ms 119168 KB Output is correct
90 Correct 1415 ms 121460 KB Output is correct
91 Correct 1494 ms 119352 KB Output is correct
92 Correct 1562 ms 119264 KB Output is correct
93 Correct 1606 ms 119288 KB Output is correct
94 Correct 1346 ms 119372 KB Output is correct
95 Correct 1512 ms 119120 KB Output is correct
96 Correct 1490 ms 121188 KB Output is correct
97 Correct 1530 ms 121480 KB Output is correct
98 Correct 1505 ms 121408 KB Output is correct
99 Correct 1509 ms 121808 KB Output is correct
100 Correct 1174 ms 113452 KB Output is correct
101 Correct 1549 ms 121568 KB Output is correct
102 Correct 1503 ms 123024 KB Output is correct
103 Correct 1591 ms 119776 KB Output is correct