답안 #1065759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065759 2024-08-19T11:31:11 Z Unforgettablepl Long Distance Coach (JOI17_coach) C++17
71 / 100
109 ms 14632 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int INF = 1e18;

struct line {
    int m,k;
    line(int m,int k):m(m),k(k){}
    int operator()(int x) const {
        return m*x+k;
    }
};

struct node {
    int L,R;
    line best;
    node *left,*right;
    node(int L,int R):L(L),R(R),left(nullptr),right(nullptr),best(0,INF){}
};

void update(node* curr,line x) {
    int mid = (curr->L+curr->R)/2;
    bool betterL = x(curr->L)<curr->best(curr->L);
    bool betterR = x(curr->R)<curr->best(curr->R);
    bool betterM = x(mid)<curr->best(mid);
    if(betterM) {
        swap(curr->best,x);
        update(curr,x);
    } else if(betterL) {
        if(curr->left==nullptr)curr->left=new node(curr->L,mid);
        update(curr->left,x);
    } else if(betterR) {
        if(curr->right==nullptr)curr->right=new node(mid+1,curr->R);
        update(curr->right,x);
    }
}

int get(node* curr,int x) {
    if(curr==nullptr)return INF;
    int mid = (curr->L+curr->R)/2;
    if(x<=mid)return min(curr->best(x),get(curr->left,x));
    return min(curr->best(x),get(curr->right,x));
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int X,N,M,W,T;
    cin >> X >> N >> M >> W >> T;
    vector<tuple<int,int,int>> arr;
    arr.emplace_back(0,0,0);
    int iterations = X/T;
    X%=T;
    arr.emplace_back(X,2,iterations);
    for(int i=1;i<=N;i++) {
        int S;cin>>S;
        arr.emplace_back(S%T,2,S/T);
    }
    for(int i=1;i<=M;i++) {
        int D,C;cin>>D>>C;
        arr.emplace_back(D,1,C);
    }
    sort(arr.begin(), arr.end());
    vector<int> DP(arr.size());
    DP[0] = (iterations+1)*W;
    node *lichao = new node(1,1e15);
    node *lichao2 = new node(1,1e18);
    int P = 0;
    int pref = 0;
    for(int i=1;i<arr.size();i++) {
        auto [pos,type,c] = arr[i];
        if(type==1) {
            if(pos<X)DP[i]=(iterations+1)*W + DP[i-1];
            else DP[i]=iterations*W + DP[i-1];
            update(lichao,{-P,DP[i-1]-pref});
            P++;
            pref+=c;
            continue;
        }
        DP[i]=DP[i-1];
        DP[i]=min(DP[i],get(lichao,c*W)+c*W*P+pref);
    }
    cout << DP.back() << '\n';
}

Compilation message

coach.cpp: In constructor 'node::node(long long int, long long int)':
coach.cpp:19:17: warning: 'node::right' will be initialized after [-Wreorder]
   19 |     node *left,*right;
      |                 ^~~~~
coach.cpp:18:10: warning:   'line node::best' [-Wreorder]
   18 |     line best;
      |          ^~~~
coach.cpp:20:5: warning:   when initialized here [-Wreorder]
   20 |     node(int L,int R):L(L),R(R),left(nullptr),right(nullptr),best(0,INF){}
      |     ^~~~
coach.cpp: In function 'int32_t main()':
coach.cpp:72:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i=1;i<arr.size();i++) {
      |                 ~^~~~~~~~~~~
coach.cpp:69:11: warning: unused variable 'lichao2' [-Wunused-variable]
   69 |     node *lichao2 = new node(1,1e18);
      |           ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 0 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 1 ms 348 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 0 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 1 ms 348 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 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 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 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 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 0 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 1 ms 348 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 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 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 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 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 544 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 0 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 1 ms 348 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 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 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 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 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 544 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Incorrect 109 ms 14632 KB Output isn't correct
53 Halted 0 ms 0 KB -