Submission #1307693

#TimeUsernameProblemLanguageResultExecution timeMemory
1307693the_commando_xSemiexpress (JOI17_semiexpress)C++17
100 / 100
80 ms66040 KiB
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

using pii = pair<int, int>;
using vii = vector<pii>;
using vvii = vector<vii>;

using l = long long;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;

using pll = pair<l, l>;
using vll = vector<pll>;
using vvll = vector<vll>;

using d = double;
using vd = vector<d>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;

using ld = long double;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;

using vb = vector<bool>;
using vvb = vector<vb>;
using pbb = pair<bool, bool>;
using vbb = vector<pbb>;

#define ff first
#define ss second

#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (!name.empty())
    {
        (void)freopen((name + ".in").c_str(), "r", stdin);
        (void)freopen((name + ".out").c_str(), "w", stdout);
    }
}

const ld pi = 3.14159265358979323846;

const l LINF = 1e18;
const l INF = 1e9;

const l MOD = 1e9 + 7;
// const l MOD = 998244353;

const l MAXN = 2e5 + 5;

void solve()
{
    l N, M, K; // * N stops for Local, M stops for Express, K stops for Semi
    cin >> N >> M >> K;

    l A, B, C; // * Time taken to travel to next station - A:Local, B:Express, C:Semi
    cin >> A >> B >> C;

    l T;
    cin >> T; // * upperbound travel time

    vl S(M); // * S[i] = Express Train Stops

    for (int i = 0; i < M; ++i)
        cin >> S[i];

    l ans = -1; // ! Removing Station 1
    priority_queue<l> q;

    for (int i = 0; i < M - 1; ++i)
    {
        l L = S[i], R = S[i + 1] - 1;

        l t0 = (L - 1) * B; // * min base time with E
        if (t0 > T)
            break;

        l x = min(R, L + (T - t0) / A); // * farthest reachable with L

        ans += x + 1 - L; // * gain after L

        /* insert SE Stop */
        int cnt = 0; // ! temporary fix for TLE
        while (x < R && cnt < 3001)
        {
            l t1 = t0 + (x + 1 - L) * C; // time to reach next stop after L (replacing inefficient path with SE - replacing [x,R])
            if (t1 > T)
                break;

            l y = min(R, x + 1 + (T - t1) / A);

            q.push(y - x); // possible gain after L

            x = y;
            ++cnt;
        }
    }

    for (int i = 0; i < K - M && q.size(); ++i)
        ans += q.top(), q.pop();

    if ((N - 1) * B <= T)
        ++ans;

    cout << max(0LL, ans);
}

int main()
{
    setIO("");

#ifndef ONLINE_JUDGE
    // setIO("filename");
#endif

    int t = 1;
    // cin >> t;
    while (t--)
        solve();

    return 0;
}

Compilation message (stderr)

semiexpress.cpp: In function 'void setIO(std::string)':
semiexpress.cpp:53:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         (void)freopen((name + ".in").c_str(), "r", stdin);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
semiexpress.cpp:54:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         (void)freopen((name + ".out").c_str(), "w", stdout);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...