답안 #786947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786947 2023-07-18T15:24:41 Z sadsa 쌀 창고 (IOI11_ricehub) C++17
0 / 100
1000 ms 3156 KB
#include "ricehub.h"

#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

using i64 = int64_t;
using vl = vector<i64>;
using ll = pair<i64, i64>;
using vll = vector<ll>;

constexpr int iINF = numeric_limits<int>::max();
constexpr i64 lINF = numeric_limits<i64>::max();

#define RANGE(x) begin(x), end(x)

template <typename... T>
void DBG(T&&... args) {
    //((cerr << args << ' '), ...) << '\n';
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &vec) {
    out << '{';
    for (size_t i = 0; i < vec.size()-1; ++i)
        out << vec[i] << ", ";
    out << vec.back() << '}';
    return out;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &pr) {
    out << '(' << pr.first << ", " << pr.second << ')';
    return out;
}

int besthub(int R, int L, int XCa[], long long B) {
    vi X(XCa, XCa + R);
    vi hub_count(L+2);

    for (auto Xi : X) {
        ++hub_count[Xi];
    }

    vi lreward(L+2);
    vl lcost(L+2);
    for (int i = 1; i <= L; ++i) {
        lreward[i] = lreward[i-1] + hub_count[i];
        lcost[i] = lcost[i-1] + lreward[i-1];
    }

    vi rreward(L+2);
    vl rcost(L+2);
    for (int i = L; i >= 1; --i) {
        rreward[i] = rreward[i+1] + hub_count[i];
        rcost[i] = rcost[i+1] + rreward[i+1];
    }

    DBG(X);
    DBG("left:");
    DBG(lreward);
    DBG(lcost);
    DBG("right:");
    DBG(rreward);
    DBG(rcost);

    auto lquery = [&] (int Xm, int Xl) {
        i64 dist = Xm-Xl;
        return pair{lreward[Xm]-lreward[Xl-1], lcost[Xm]-lcost[Xl]-dist*lreward[Xl-1]};
    };

    auto rquery = [&] (int Xm, int Xr) {
        i64 dist = Xr-Xm;
        return pair{rreward[Xm]-rreward[Xr+1], rcost[Xm]-rcost[Xr]-dist*rreward[Xr+1]};
    };

    auto range_query = [&] (int Xm, int Xl, int Xr) {
        auto [lr, lc] = lquery(Xm, Xl);
        auto [rr, rc] = rquery(Xm, Xr);

        return pair{lr+rr-hub_count[Xm], lc+rc};
    };

    int xbeg = X.front();
    int xend = X.back();

    int ans = 0;
    for (int xl = xbeg; xl <= xend; ++xl) {
        for (int xr = xl; xr <= xend; ++xr) {
            for (int x = xl; x <= xr; ++x) {
                auto [reward, cost] = range_query(x, xl, xr);
                if (cost <= B) {
                    if (reward > ans) {
                        DBG("pos:", x, xl, xr);
                        DBG("rice+cost:", reward, cost);
                        ans = reward;
                    }
                } else {
                    xr = xend;
                    break;
                }
            }
        }
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 17 ms 316 KB Output is correct
4 Incorrect 14 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 3156 KB Time limit exceeded
2 Halted 0 ms 0 KB -