답안 #416221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416221 2021-06-02T08:03:00 Z Aldas25 Long Distance Coach (JOI17_coach) C++14
71 / 100
2000 ms 19808 KB
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 200100, MAXK = 30;
//const ll MOD = 998244353;
const ll INF = 4e18;
const ld PI = asin(1) * 2;

ll x, n, m, w, t;
ll s[MAXN];
vector<pair<ll, ll>> tmp;
ll firstStop[MAXN];
ll dp[MAXN][2];
ll d[MAXN], c[MAXN];
ll prefC[MAXN];
ll waterDrunk[MAXN];

int main()
{
    FAST_IO;

    cin >> x >> n >> m >> w >> t;
    //cout << " x=" << x << " n=" << n  << " m="<< m  << " w=" << w  << " t="<< t << endl;
    FOR(i, 1, n) cin >> s[i];
    sort(s+1, s+n+1);
    s[++n] = x; /// the finish
    //cout << " n = " << n << " m = " << m << endl;
    REP(m) {
      //  cout << " here " << endl;
        ll dd =-1, cc = -1;
        cin >> dd >> cc;
        //cout << "   dd = " << dd << " cc = " << cc << endl;
        tmp.pb({dd, cc});
    }
    sort(tmp.begin(), tmp.end());
    tmp.pb({0, 0}); /// driver
    m++;
    FOR(i, 0, m-1) {
        d[i+1] = tmp[i].f;
        c[i+1] = tmp[i].s;
    }
    FOR(i, 1, m) prefC[i] = prefC[i-1] + c[i];


    FOR(i, 1, n) {
        ll pos = s[i]%t;
        ll latest = m;
        if (d[1] < pos) {
            int le = 1, ri = m-1;
            while (le < ri) {
                int mid = (le+ri+1)/2;
                if (d[mid] < pos) le = mid;
                else ri = mid-1;
            }
            latest = le;
        }

        if (firstStop[latest] == 0) {
            firstStop[latest] = i;
        }

        waterDrunk[i] = (s[i]-1) / t;
        waterDrunk[i] *= m;
        waterDrunk[i]++;
        if(latest < m) waterDrunk[i] += latest;
        waterDrunk[i] *= w;

        //cout << "  i = " << i << " s="<< s[i] << " waterDrunk = " << waterDrunk[i] << "  latest = " << latest << endl;
    }

    //FOR(i, 1, m) cout << "     i = " << i << "  firstStop = " << firstStop[i] << endl;

    FOR(i, 1, m) {
        ll waterThis = (x/t) + (d[i] < (x%t));
        waterThis *= w;

        dp[i][1] = waterThis + min(dp[i-1][0], dp[i-1][1]);
        dp[i][0] = dp[i][1];

        if (firstStop[i] == 0) {
           // cout << " i = " << i << " d = " << d[i] << "  dp0 = dp1 = " << dp[i][1]  << "  (in cont) " << endl;
            continue; /// cannot take since d[i-1] is never an end before a stop
        }

        FOR(j, 0, i-1) {
            ll water = (s[firstStop[i]] - 1) / t;
            //water ++;
            water *= (ll)(i-j);
            water *= w;
            ll cur = min(dp[j][0], dp[j][1]) + water + prefC[i] - prefC[j];
            dp[i][0] = min(dp[i][0], cur);

            //cout << "    i = " << i << " j = " << j << " cur = " << cur  << "    water = " << water << endl;
        }

        //cout << " i = " << i << " d = " << d[i] << "   dp0 = " << dp[i][0] << " dp1 = " << dp[i][1] << endl;
    }

    cout << dp[m][1] << "\n";

    return 0;
}

/*
1000000000000 1 1 1000000 6
999999259244
1 123456789
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 4 ms 600 KB Output is correct
39 Correct 7 ms 608 KB Output is correct
40 Correct 6 ms 612 KB Output is correct
41 Correct 4 ms 588 KB Output is correct
42 Correct 3 ms 588 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 4 ms 588 KB Output is correct
45 Correct 3 ms 588 KB Output is correct
46 Correct 5 ms 588 KB Output is correct
47 Correct 5 ms 588 KB Output is correct
48 Correct 4 ms 588 KB Output is correct
49 Correct 3 ms 588 KB Output is correct
50 Correct 4 ms 588 KB Output is correct
51 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 4 ms 600 KB Output is correct
39 Correct 7 ms 608 KB Output is correct
40 Correct 6 ms 612 KB Output is correct
41 Correct 4 ms 588 KB Output is correct
42 Correct 3 ms 588 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 4 ms 588 KB Output is correct
45 Correct 3 ms 588 KB Output is correct
46 Correct 5 ms 588 KB Output is correct
47 Correct 5 ms 588 KB Output is correct
48 Correct 4 ms 588 KB Output is correct
49 Correct 3 ms 588 KB Output is correct
50 Correct 4 ms 588 KB Output is correct
51 Correct 4 ms 588 KB Output is correct
52 Execution timed out 2070 ms 19808 KB Time limit exceeded
53 Halted 0 ms 0 KB -