답안 #600754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600754 2022-07-21T07:36:57 Z 이동현(#8470) Long Distance Coach (JOI17_coach) C++17
0 / 100
8 ms 9736 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int NS = (int)2e5 + 4;
int x, n, m, w, t;
int r[NS];
int s[NS];
vector<int> peo[NS];
int dp[NS];
int A[NS], B[NS];

vector<int> line[NS];
int lineN, f;

int cross(vector<int> x, vector<int> y){
    return (y[1] - x[1]) / (x[0] - y[0]);
}

void push(int a, int b){
    while(lineN - f >= 2 && cross(line[lineN - 1], line[lineN - 2]) >= cross({a, b}, line[lineN - 1])) --lineN;
    line[lineN++] = {a, b};
}

int get(int x){
    if(f == lineN) return (int)1e18;
    while(lineN - f >= 2 && x >= cross(line[f + 1], line[f])) ++f;
    return line[f][0] * x + line[f][1];
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> x >> n >> m >> w >> t;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    ++n; s[n] = x;
    for(int i = 1; i <= m; ++i){
        peo[i].resize(2);
        cin >> peo[i][0] >> peo[i][1];
    }
    sort(s + 1, s + n + 1, [&](int&x, int&y){return x % t < y % t;});
    sort(peo + 1, peo + m + 1);
    int pp = 0;
    for(int i = 1; i <= n; ++i){
        while(pp + 1 <= m && peo[pp + 1][0] < s[i] % t){
            ++pp;
        }
        r[i] = pp;
    }
    auto eat = [&](int all, int me)->int{
        if(all >= me) return (all - me) / t + 1;
        return 0;
    };
    for(int i = 1; i <= m; ++i){
        A[i] = w * eat(x, peo[i][0]);
        A[i] += A[i - 1];
        B[i] = peo[i][1] - w * eat(x, peo[i][0]);
        B[i] += B[i - 1];
    }
    int ans = A[m];
    int ikmn = 0;
    for(int j = 0; j < r[1]; ++j){
        push(-j, ikmn - B[j]);
    }
    for(int i = 1; i <= n; ++i){
        int X = w * (s[i] / t);
        dp[i] = get(X) + X * r[i] + A[r[i]] + B[r[i]];
        dp[i] = min(dp[i], ikmn + A[r[i]]);
        ikmn = min(ikmn, dp[i] - A[r[i]]);
        if(i < n){
            for(int j = r[i]; j < r[i + 1]; ++j){
                push(-j, ikmn - B[j]);
            }
        }

        int nval = dp[i] + A[m] - A[r[i]];
        ans = min(ans, nval);
    }
    ans += w * eat(x, 0);
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9736 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9688 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 8 ms 9736 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9736 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9688 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 8 ms 9736 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9736 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9688 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 8 ms 9736 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9736 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9688 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 8 ms 9736 KB Output isn't correct
8 Halted 0 ms 0 KB -