結果

問題 No.9 モンスターのレベル上げ
ユーザー MisterMister
提出日時 2020-08-19 19:54:08
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 280 ms / 5,000 ms
コード長 1,052 bytes
コンパイル時間 821 ms
使用メモリ 3,640 KB
最終ジャッジ日時 2022-12-05 06:59:35
合計ジャッジ時間 4,677 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,404 KB
testcase_01 AC 1 ms
3,400 KB
testcase_02 AC 280 ms
3,620 KB
testcase_03 AC 225 ms
3,620 KB
testcase_04 AC 115 ms
3,440 KB
testcase_05 AC 77 ms
3,576 KB
testcase_06 AC 26 ms
3,524 KB
testcase_07 AC 1 ms
3,520 KB
testcase_08 AC 35 ms
3,532 KB
testcase_09 AC 271 ms
3,576 KB
testcase_10 AC 2 ms
3,396 KB
testcase_11 AC 230 ms
3,536 KB
testcase_12 AC 175 ms
3,472 KB
testcase_13 AC 176 ms
3,620 KB
testcase_14 AC 273 ms
3,472 KB
testcase_15 AC 250 ms
3,468 KB
testcase_16 AC 5 ms
3,460 KB
testcase_17 AC 159 ms
3,456 KB
testcase_18 AC 135 ms
3,640 KB
testcase_19 AC 3 ms
3,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n), ys(n);
    for (auto& x : xs) std::cin >> x;
    for (auto& y : ys) std::cin >> y;

    int ans = n;
    for (int q = 0; q < n; ++q) {
        auto nxs = xs;
        std::vector<int> match(n, 0);

        MinHeap<std::tuple<int, int, int>> heap;
        for (int i = 0; i < n; ++i) heap.emplace(nxs[i], match[i], i);

        for (auto y : ys) {
            auto [x, m, i] = heap.top();
            heap.pop();

            nxs[i] += y / 2;
            ++match[i];
            heap.emplace(nxs[i], match[i], i);
        }

        ans = std::min(ans, *std::max_element(match.begin(), match.end()));

        std::rotate(ys.begin(), ys.begin() + 1, ys.end());
    }

    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0