답안 #698155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698155 2023-02-12T15:26:48 Z finn__ City (BOI06_city) C++17
70 / 100
5 ms 468 KB
#include <bits/stdc++.h>
using namespace std;

vector<uint64_t> c;

pair<uint64_t, uint64_t> num_assignable_workers(
    uint64_t n, uint64_t t, uint64_t max_cost)
{
    uint64_t total_cost = 0, w = 0;

    for (size_t i = 0; i < c.size() && w < n; i++)
    {
        if (c[i] > max_cost)
            break;
        uint64_t d = (max_cost - c[i]) / t,
                 num_workers = 2 * ((d + 1) * (d + 1) + d + 1);
        w += num_workers;
        total_cost += num_workers * c[i] +
                      t * 2 * (d * (d + 1) * (2 * d + 1) / 3 + d * (d + 1));
    }

    return {w, total_cost};
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    uint64_t n, t, k;
    cin >> n >> t >> k;

    c = vector<uint64_t>(k);
    for (uint64_t &x : c)
        cin >> x;

    // Search for the maximal cost, such that almost all workers can be assigned.
    // The remaining ones must take a house with one additional distance.
    uint64_t a = 0, b = 2000000000;
    while (a < b)
    {
        uint64_t mid = (a + b + 1) / 2;
        if (num_assignable_workers(n, t, mid).first < n)
            a = mid;
        else
            b = mid - 1;
    }

    auto const [w, total_cost] = num_assignable_workers(n, t, a);
    cout << total_cost + (n - w) * (a + 1) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Correct 5 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct