Submission #1065750

# Submission time Handle Problem Language Result Execution time Memory
1065750 2024-08-19T11:28:58 Z Unforgettablepl Long Distance Coach (JOI17_coach) C++17
16 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int INF = 1e18+1e17;

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,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:71: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]
   71 |     for(int i=1;i<arr.size();i++) {
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 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 0 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 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 0 ms 348 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 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 0 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 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 0 ms 348 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 0 ms 348 KB Output is correct
24 Incorrect 0 ms 348 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 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 0 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 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 0 ms 348 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 0 ms 348 KB Output is correct
24 Incorrect 0 ms 348 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 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 0 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 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 0 ms 348 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 0 ms 348 KB Output is correct
24 Incorrect 0 ms 348 KB Output isn't correct
25 Halted 0 ms 0 KB -