Submission #1280011

#TimeUsernameProblemLanguageResultExecution timeMemory
1280011icebearSemiexpress (JOI17_semiexpress)C++20
100 / 100
64 ms33328 KiB
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

template<class T>
    bool minimize(T &a, const T &b) {
        if (a > b) return a = b, true;
        return false;
    }

template<class T>
    bool maximize(T &a, const T &b) {
        if (a < b) return a = b, true;
        return false;
    }

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
/*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN VOI26 */

const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 3000 + 5;
int numStop, numExp, numSemi, costLocal, costExp, costSemi;
ll budget, station[N];

void init(void) {
    cin >> numStop >> numExp >> numSemi >> costLocal >> costExp >> costSemi >> budget;
    FOR(i, 1, numExp) cin >> station[i];
}

void process(void) {
    ll res = 0;
    vector<ll> reach;

    if (1LL * (numStop - 1) * costExp <= budget) res = 1;
    FOR(i, 1, numExp - 1) {
        ll initCost = (station[i] - 1) * costExp;
        if (initCost > budget) break;
        ll maxReach = (budget - initCost) / costLocal;

        res += min(station[i + 1] - 1 - station[i], maxReach);
        if (i > 1 && initCost <= budget) res++;
//        cerr << initCost << ' ' << min((ll)station[i + 1] -  1 - station[i], maxReach) << '\n';

        if (station[i] + maxReach >= station[i + 1]) continue;
        ll curPos = station[i] + maxReach + 1;
        REP(tries, numSemi) {
            ll newCost = initCost + (curPos - station[i]) * costSemi;
            if (newCost > budget) break;
            ll newReach = (budget - newCost) / costLocal;
//            cerr << "DEBUG : " << curPos << ' ' << newCost << ' ' <<  newReach << "  -- FROM : " << station[i] << " -> TO : " << station[i + 1] << " CREATE : " << min(station[i + 1] - curPos, newReach + 1) << '\n';

            reach.push_back(min(station[i + 1] - curPos, newReach + 1));
            curPos += newReach + 1;
            if (curPos > station[i + 1]) break;
        }
    }

    REP(i, numSemi - numExp) reach.push_back(0);
    sort(all(reach), greater<ll>());
    REP(i, numSemi - numExp) res += reach[i];
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int tc = 1;
//    cin >> tc;
    while(tc--) {
        init();
        process();
    }
    return 0;
}

Compilation message (stderr)

semiexpress.cpp: In function 'int main()':
semiexpress.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
semiexpress.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...