답안 #491307

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491307 2021-12-01T13:08:22 Z blue 치료 계획 (JOI20_treatment) C++17
35 / 100
622 ms 109024 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <queue>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
 
struct project
{
    int T;
    int L;
    int R;
    int C;
    int I;
};
 
 
 
vector<project> P;
 
const int maxM = 200'000;
vi query_ans;
 
vi visited(maxM, 0);
 
const ll INF = 1'000'000'000'000'000'000LL;
 
vll dp(maxM, INF);
 
struct pos
{
    int i;
};
 
bool operator < (pos A, pos B)
{
    if(dp[A.i] == dp[B.i]) return A.i < B.i;
    else return dp[A.i] < dp[B.i];
}
 
 
 
struct segtree
{
    // deque<int> v[220'000];
    vector<int> v[1 << 20];
 
    segtree()
    {
        ;
    }
 
    segtree(int L, int R)
    {
        ;
    }
 
    void add(int i, int l, int r, int I, ll Pr)
    {
        v[i].push_back(Pr);
        if(l != r)
        {
            if(I <= (l+r)/2) add(2*i, l, (l+r)/2, I, Pr);
            else add(2*i + 1, (l+r)/2+1, r, I, Pr);
        }
    }
 
    void getU(int i, int l, int r, int L, int R, ll mxv)
    {
        if(R < l || r < L || R < L) return;
        else if(L <= l && r <= R)
        {
            while(1)
            {
                if(v[i].empty()) break;
                if(P[v[i].back()].L + P[v[i].back()].T > mxv) break;
                if(!visited[v[i].back()])
                {
                    query_ans.push_back(v[i].back());
                    visited[v[i].back()] = 1;
                }
                v[i].pop_back();
            }
        }
        else
        {
            getU(2*i, l, (l+r)/2, L, R, mxv);
            getU(2*i+1, (l+r)/2+1, r, L, R, mxv);
        }
    }
 
    void getD(int i, int l, int r, int L, int R, ll mxv)
    {
        if(R < l || r < L || R < L) return;
        else if(L <= l && r <= R)
        {
            while(1)
            {
                if(v[i].empty()) break;
                if(P[v[i].back()].L - P[v[i].back()].T > mxv) break;
                if(!visited[v[i].back()])
                {
                    query_ans.push_back(v[i].back());
                    visited[v[i].back()] = 1;
                }
                v[i].pop_back();
            }
        }
        else
        {
            getD(2*i, l, (l+r)/2, L, R, mxv);
            getD(2*i+1, (l+r)/2+1, r, L, R, mxv);
        }
    }
};
 
segtree U, D;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int N, M;
    cin >> N >> M;
 
    P = vector<project>(M);
    for(int i = 0; i < M; i++) cin >> P[i].T >> P[i].L >> P[i].R >> P[i].C;
 
    sort(P.begin(), P.end(), [] (project x, project y)
    {
        return x.T < y.T;
    });
 
    for(int i = 0; i < M; i++) P[i].I = i;
 
 
    sort(P.begin(), P.end(), [] (project x, project y)
    {
        return x.L + x.T <= y.L + y.T;
    });
 
    for(int i = 0; i < M; i++)
        U.add(1, 0, M-1, P[i].I, P[i].I);
 
    sort(P.begin(), P.end(), [] (project x, project y)
    {
        return x.L - x.T < y.L - y.T;
    });
 
    for(int i = 0; i < M; i++)
        D.add(1, 0, M-1, P[i].I, P[i].I);
 
    for(int f = 0; f < (1 << 20); f++)
    {
        reverse(U.v[f].begin(), U.v[f].end());
        reverse(D.v[f].begin(), D.v[f].end());
    }
 
 
 
    sort(P.begin(), P.end(), [] (project x, project y)
    {
        return x.I < y.I;
    });
 
    for(int i = 0; i < M; i++)
    {
        if(P[i].L == 1)
        {
            dp[i] = P[i].C;
            visited[i] = 1;
        }
    }
 
 
    set<pos> tbv;
    for(int i = 0; i < M; i++) tbv.insert(pos{i});
 
    while(!tbv.empty())
    {
        int u = tbv.begin()->i;
        tbv.erase(tbv.begin());
        // cerr << "visiting " << u << ' ' << P[u].L << ' ' << P[u].R <<  '\n';
 
 
        if(!visited[u]) break;
 
 
        query_ans.clear();
        U.getU(1, 0, M-1, u+1, M-1, P[u].R + P[u].T + 1);
        D.getD(1, 0, M-1, 0, u-1, P[u].R - P[u].T + 1);
 
        for(int v: query_ans)
        {
            if(tbv.find(pos{v}) == tbv.end()) continue;
            // cerr << u << " -> " << v << '\n';
            if(P[v].L <= P[u].R + 1 - abs(P[u].T - P[v].T))
            {
                if(dp[v] > dp[u] + P[v].C)
                {
                    tbv.erase(pos{v});
                    dp[v] = dp[u] + P[v].C;
                    tbv.insert(pos{v});
                }
            }
        }
    }
 
    ll final_ans = INF;
    for(int i = 0; i < M; i++)
        if(P[i].R == N)
            final_ans = min(final_ans, dp[i]);
 
    if(final_ans >= INF) final_ans = -1;
 
    cout << final_ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 622 ms 84584 KB Output is correct
2 Correct 391 ms 84628 KB Output is correct
3 Runtime error 114 ms 109024 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 51916 KB Output is correct
2 Correct 31 ms 51916 KB Output is correct
3 Correct 32 ms 51916 KB Output is correct
4 Correct 33 ms 51812 KB Output is correct
5 Correct 31 ms 51852 KB Output is correct
6 Correct 31 ms 51904 KB Output is correct
7 Correct 29 ms 51916 KB Output is correct
8 Correct 33 ms 51912 KB Output is correct
9 Correct 34 ms 51824 KB Output is correct
10 Correct 33 ms 51840 KB Output is correct
11 Correct 31 ms 51840 KB Output is correct
12 Correct 36 ms 51872 KB Output is correct
13 Correct 31 ms 51844 KB Output is correct
14 Correct 29 ms 51916 KB Output is correct
15 Correct 29 ms 51836 KB Output is correct
16 Correct 36 ms 51916 KB Output is correct
17 Correct 30 ms 51860 KB Output is correct
18 Correct 31 ms 51840 KB Output is correct
19 Correct 29 ms 51848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 51916 KB Output is correct
2 Correct 31 ms 51916 KB Output is correct
3 Correct 32 ms 51916 KB Output is correct
4 Correct 33 ms 51812 KB Output is correct
5 Correct 31 ms 51852 KB Output is correct
6 Correct 31 ms 51904 KB Output is correct
7 Correct 29 ms 51916 KB Output is correct
8 Correct 33 ms 51912 KB Output is correct
9 Correct 34 ms 51824 KB Output is correct
10 Correct 33 ms 51840 KB Output is correct
11 Correct 31 ms 51840 KB Output is correct
12 Correct 36 ms 51872 KB Output is correct
13 Correct 31 ms 51844 KB Output is correct
14 Correct 29 ms 51916 KB Output is correct
15 Correct 29 ms 51836 KB Output is correct
16 Correct 36 ms 51916 KB Output is correct
17 Correct 30 ms 51860 KB Output is correct
18 Correct 31 ms 51840 KB Output is correct
19 Correct 29 ms 51848 KB Output is correct
20 Correct 40 ms 53368 KB Output is correct
21 Correct 47 ms 53448 KB Output is correct
22 Correct 42 ms 53472 KB Output is correct
23 Correct 40 ms 53436 KB Output is correct
24 Correct 44 ms 53488 KB Output is correct
25 Correct 43 ms 53400 KB Output is correct
26 Correct 43 ms 53400 KB Output is correct
27 Correct 52 ms 53436 KB Output is correct
28 Correct 51 ms 53556 KB Output is correct
29 Correct 45 ms 53424 KB Output is correct
30 Correct 39 ms 53356 KB Output is correct
31 Correct 38 ms 53472 KB Output is correct
32 Correct 46 ms 53412 KB Output is correct
33 Correct 45 ms 53444 KB Output is correct
34 Correct 43 ms 53452 KB Output is correct
35 Correct 45 ms 53392 KB Output is correct
36 Correct 52 ms 53408 KB Output is correct
37 Correct 49 ms 53396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 622 ms 84584 KB Output is correct
2 Correct 391 ms 84628 KB Output is correct
3 Runtime error 114 ms 109024 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -