Submission #520425

# Submission time Handle Problem Language Result Execution time Memory
520425 2022-01-29T23:55:27 Z ajpiano Long Distance Coach (JOI17_coach) C++17
71 / 100
2000 ms 16080 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;
    sort(stops.begin(), stops.end());

    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];
            dp[i] = min(dp[i], dp[j+1]+dist*coe[stop]);
        }
    }

    //give ans
    cout << ans+dp[1] << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 316 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 0 ms 208 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 0 ms 208 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 316 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 0 ms 208 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 0 ms 208 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 208 KB Output is correct
38 Correct 6 ms 452 KB Output is correct
39 Correct 8 ms 336 KB Output is correct
40 Correct 8 ms 460 KB Output is correct
41 Correct 7 ms 336 KB Output is correct
42 Correct 6 ms 376 KB Output is correct
43 Correct 6 ms 348 KB Output is correct
44 Correct 6 ms 464 KB Output is correct
45 Correct 6 ms 336 KB Output is correct
46 Correct 9 ms 360 KB Output is correct
47 Correct 8 ms 360 KB Output is correct
48 Correct 9 ms 456 KB Output is correct
49 Correct 6 ms 376 KB Output is correct
50 Correct 7 ms 460 KB Output is correct
51 Correct 7 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 316 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 0 ms 208 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 0 ms 208 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 208 KB Output is correct
38 Correct 6 ms 452 KB Output is correct
39 Correct 8 ms 336 KB Output is correct
40 Correct 8 ms 460 KB Output is correct
41 Correct 7 ms 336 KB Output is correct
42 Correct 6 ms 376 KB Output is correct
43 Correct 6 ms 348 KB Output is correct
44 Correct 6 ms 464 KB Output is correct
45 Correct 6 ms 336 KB Output is correct
46 Correct 9 ms 360 KB Output is correct
47 Correct 8 ms 360 KB Output is correct
48 Correct 9 ms 456 KB Output is correct
49 Correct 6 ms 376 KB Output is correct
50 Correct 7 ms 460 KB Output is correct
51 Correct 7 ms 464 KB Output is correct
52 Execution timed out 2075 ms 16080 KB Time limit exceeded
53 Halted 0 ms 0 KB -