제출 #1294895

#제출 시각아이디문제언어결과실행 시간메모리
1294895lrnnz나일강 (IOI24_nile)C++20
67 / 100
2089 ms9772 KiB
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <random>
#include "nile.h"
using namespace std;

#define all(a) (a).begin(), (a).end()
#define ll long long
#define ld long double
#define ui __int128_t
#define cont(set, element) ((set).find(element) != (set).end())
#define pb push_back

template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/********* DEBUG *********/

template <typename T>
void outvec(const vector<T>& Z){
    for (const T& x : Z)
    cout << x << ' ';
    cout << "\n";
}
void printVariable(const any& var) {
    if (!var.has_value()) {
        cout << "null";
        return;
    }

    if (var.type() == typeid(int)) {
        cout << any_cast<int>(var);
    } else if (var.type() == typeid(double)) {
        cout << any_cast<double>(var);
    } else if (var.type() == typeid(float)) {
        cout << any_cast<float>(var);
    } else if (var.type() == typeid(char)) {
        cout << any_cast<char>(var);
    } else if (var.type() == typeid(bool)) {
        cout << (any_cast<bool>(var) ? "true" : "false");
    } else if (var.type() == typeid(string)) {
        cout << any_cast<string>(var);
    } else if (var.type() == typeid(const char*)) {
        cout << any_cast<const char*>(var);
    } else if (var.type() == typeid(long long)) {
        cout << any_cast<long long>(var);
    } else {
        cout << "[unknown type]";
    }
}


template<typename... Args>
void outval(Args... args) {
    vector<any> variables = {args...};

    for (size_t i = 0; i < variables.size(); ++i) {
        printVariable(variables[i]);
        if (i != variables.size() - 1) {
            cout << " ";
        }
    }
    cout << "\n";
}

/********* DEBUG *********/

#define sp << " " <<
#define fi first
#define se second

const ll MOD2 = 1e9 + 7;
const ll MOD = 998244353;
const ll inf = 1e18;

ll madd(ll a, ll b) { a += b; if (a >= MOD) a -= MOD; return a; }
ll msub(ll a, ll b) { a -= b; if (a < 0) a += MOD; return a ; }
ll mmul(ll a, ll b) { return 1ll * a * b % MOD; }
ll mpow(ll a, ll b) { ll ans = 1; for (; b; b >>= 1, a = mmul(a, a)) if (b & 1) ans = mmul(ans, a); return ans; }

vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
    ll Q = E.size(), n = W.size();
    vector<ll> ans(Q), ord(n);

    iota(all(ord), 0);
    sort(all(ord), [&](ll i, ll j) {
        return W[i] < W[j];
    });
    
    ll sum = 0;
    for (int i = 0; i < n; i++)
        sum += A[i];

    // max we can remove from sum
    vector<vector<ll>> dp(2, vector<ll>(n));
    for (int q = 0; q < Q; q++) {
        ll D = E[q];
        for (int i = 0; i < n; i++) 
            dp[0][i] = dp[1][i] = -inf;
        dp[0][0] = 0;

        ll l = 0;
        multiset<ll> s;
        for (int i = 0; i < n; i++) {
            ll j = ord[i];

            if (i) dp[0][i] = max(dp[0][i-1], dp[1][i-1]);
            while (W[j] - W[ord[l]] > D) {
                ll v = A[ord[l]] - B[ord[l]] + (l ? max(dp[0][l-1], dp[1][l-1]) : 0);
                s.extract(v);
                l++;
            }   

            if (s.size()) {
                ll v = *s.rbegin();
                dp[1][i] = v + A[j] - B[j];
            }

            ll v = A[j] - B[j] + (i ? max(dp[0][i-1], dp[1][i-1]) : 0);
            s.insert(v);
        }

        ans[q] = sum - max(dp[0][n-1], dp[1][n-1]);
    }

    return ans;
}  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...