답안 #520423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520423 2022-01-29T23:45:56 Z ajpiano Long Distance Coach (JOI17_coach) C++17
0 / 100
1 ms 336 KB
//https://oj.uz/problem/view/JOI17_coach
#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //remember to include destination in dp
    //remember to add driver cost
    ll x, w, t; int n,m; cin >> x >> n >> m >> w >> t; //Total time, cities, people, water cost, time interval

    vector<ll> stops(n+1); //where the coach stops
    for(int i = 0; i < n; i++) cin >> stops[i];
    stops[n] = x;

    vector<pi> passengers(m+1); // water time, refund cost
    for(int i = 1; i <= m; i++) cin >> passengers[i].f >> passengers[i].s;
    sort(passengers.begin(), passengers.end());

    //find from where you can go back on a passenger
    vector<int> goback(m+1,-1);
    for(int i = n; i >= 0; i--){
        ll pos = stops[i]%t;
        pi fnd = {pos,0};
        int cur = lower_bound(passengers.begin(), passengers.end(), fnd) - passengers.begin()-1; //passenger you can go back from
        goback[cur] = i;
    }

    //find coefficient for each stop
    vector<ll> coe(n+1);
    for(int i = 0; i <= n; i++) coe[i] = w*(stops[i]/t);

    //find full cost for each passenger
    vector<ll> cost(m+1);
    for(int i = 0; i <= m; i++){
        cost[i] = w*((x-passengers[i].f)/t+1LL)-passengers[i].s;
    }

    ll ans = 0;
    //assume you refund everyone
    for(int i = 0; i <= m; i++) ans += passengers[i].s;
    //add driver cost
    ans += cost[0];

    vector<ll> dp(m+2);

    //do dp
    for(int i = m; i > 0; i--){
        dp[i] = cost[i]+dp[i+1];
        for(int j = i; j <= m; j++){
            if(goback[j] == -1) continue;
            ll dist = j-i+1;
            int stop = goback[j];
            ll pcur = dp[i];
            dp[i] = min(dp[i], dp[j+1]+dist*coe[stop]);
        }
    }

    //give ans
    cout << ans+dp[1] << "\n";
    return 0;
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:61:16: warning: unused variable 'pcur' [-Wunused-variable]
   61 |             ll pcur = dp[i];
      |                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Incorrect 0 ms 208 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Incorrect 0 ms 208 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Incorrect 0 ms 208 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Incorrect 0 ms 208 KB Output isn't correct
8 Halted 0 ms 0 KB -