結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー milanis48663220milanis48663220
提出日時 2021-11-12 22:17:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 594 ms / 3,000 ms
コード長 2,344 bytes
コンパイル時間 1,053 ms
コンパイル使用メモリ 125,444 KB
実行使用メモリ 8,436 KB
最終ジャッジ日時 2024-05-04 09:14:49
合計ジャッジ時間 9,844 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 483 ms
8,320 KB
testcase_05 AC 583 ms
8,316 KB
testcase_06 AC 27 ms
7,052 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 73 ms
5,916 KB
testcase_09 AC 122 ms
7,836 KB
testcase_10 AC 332 ms
5,524 KB
testcase_11 AC 10 ms
5,376 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 18 ms
5,376 KB
testcase_14 AC 357 ms
7,572 KB
testcase_15 AC 316 ms
8,312 KB
testcase_16 AC 334 ms
5,376 KB
testcase_17 AC 172 ms
5,740 KB
testcase_18 AC 386 ms
5,588 KB
testcase_19 AC 93 ms
5,856 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 200 ms
7,776 KB
testcase_22 AC 316 ms
8,088 KB
testcase_23 AC 522 ms
8,312 KB
testcase_24 AC 558 ms
8,312 KB
testcase_25 AC 578 ms
8,316 KB
testcase_26 AC 30 ms
6,908 KB
testcase_27 AC 594 ms
8,304 KB
testcase_28 AC 29 ms
7,168 KB
testcase_29 AC 568 ms
8,308 KB
testcase_30 AC 552 ms
8,436 KB
testcase_31 AC 30 ms
6,908 KB
testcase_32 AC 29 ms
6,920 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using P = pair<ll, int>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    ll a, b, x, y; cin >> a >> b >> x >> y;
    vector<ll> w(n);
    for(int i = 0; i < n; i++) {
        cin >> w[i];
    }
    auto ok = [&](ll p, int a){
        vector<ll> h(n);
        priority_queue<P> que;
        for(int i = 0; i < n; i++){
            h[i] = max(0ll, w[i]-p);
        }
        for(int i = 0; i < n; i++) {
            que.push(P(h[i], i));
        }
        while(a > 0 && !que.empty()){
            auto [_, i] = que.top(); que.pop();
            a--;
            h[i] -= x;
            if(h[i] <= 0) continue;
            que.push(P(h[i], i));
        }
        for(int i = 0; i < n; i++){
            if(h[i] <= 0) h[i] = 0;
        }
        ll sum = accumulate(h.begin(),  h.end(), 0ll);
        return sum <= y*b;
    };
    if(ok(0, a)){
        cout << 0 << endl;
        return 0;
    }
    ll h_max = *max_element(w.begin(), w.end());
    ll l = 0, r = h_max;
    while(r-l > 1){
        ll x = (l+r)/2;
        if(ok(x, a)) r = x;
        else l = x;
    }
    cout << r << endl;
}
0