結果

問題 No.9 モンスターのレベル上げ
ユーザー MisterMister
提出日時 2020-08-19 19:54:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 5,000 ms
コード長 1,052 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 92,076 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 09:49:50
合計ジャッジ時間 4,591 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 298 ms
5,376 KB
testcase_03 AC 238 ms
5,376 KB
testcase_04 AC 124 ms
5,376 KB
testcase_05 AC 81 ms
5,376 KB
testcase_06 AC 28 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 37 ms
5,376 KB
testcase_09 AC 289 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 244 ms
5,376 KB
testcase_12 AC 199 ms
5,376 KB
testcase_13 AC 172 ms
5,376 KB
testcase_14 AC 292 ms
5,376 KB
testcase_15 AC 266 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 171 ms
5,376 KB
testcase_18 AC 142 ms
5,376 KB
testcase_19 AC 4 ms
5,376 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