結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー koba-e964koba-e964
提出日時 2021-11-12 22:13:41
言語 Rust
(1.77.0)
結果
AC  
実行時間 263 ms / 3,000 ms
コード長 1,905 bytes
コンパイル時間 10,659 ms
コンパイル使用メモリ 397,524 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-04 09:09:14
合計ジャッジ時間 17,290 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 0 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 253 ms
6,940 KB
testcase_05 AC 258 ms
6,944 KB
testcase_06 AC 49 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 135 ms
6,940 KB
testcase_09 AC 219 ms
6,940 KB
testcase_10 AC 88 ms
6,944 KB
testcase_11 AC 66 ms
6,944 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 154 ms
6,944 KB
testcase_14 AC 179 ms
6,944 KB
testcase_15 AC 263 ms
6,944 KB
testcase_16 AC 62 ms
6,940 KB
testcase_17 AC 118 ms
6,940 KB
testcase_18 AC 116 ms
6,944 KB
testcase_19 AC 100 ms
6,944 KB
testcase_20 AC 49 ms
6,944 KB
testcase_21 AC 198 ms
6,940 KB
testcase_22 AC 226 ms
6,940 KB
testcase_23 AC 252 ms
6,944 KB
testcase_24 AC 252 ms
6,940 KB
testcase_25 AC 249 ms
6,944 KB
testcase_26 AC 253 ms
6,944 KB
testcase_27 AC 248 ms
6,940 KB
testcase_28 AC 255 ms
6,940 KB
testcase_29 AC 254 ms
6,944 KB
testcase_30 AC 260 ms
6,940 KB
testcase_31 AC 250 ms
6,940 KB
testcase_32 AC 251 ms
6,944 KB
testcase_33 AC 1 ms
6,940 KB
testcase_34 AC 0 ms
6,944 KB
testcase_35 AC 1 ms
6,940 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 1 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 1 ms
6,940 KB
testcase_40 AC 1 ms
6,944 KB
testcase_41 AC 1 ms
6,944 KB
testcase_42 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn calc(a: i64, b: i64, x: i64, y: i64, h: &[i64]) -> bool {
    let n = h.len();
    let mut a = a;
    let mut q = 0;
    let mut v = vec![];
    let mut s = 0;
    for i in 0..n {
        q += h[i] / x;
        v.push(h[i] % x);
        s += h[i];
    }
    v.sort();
    let r = min(a, q);
    a -= r;
    q -= r;
    s -= r * x;
    if a > 0 {
        assert_eq!(q, 0);
        for i in 0..min(a as usize, n) {
            s -= v[n - 1 - i];
        }
    }
    s <= b * y
}

fn main() {
    input! {
        n: usize, a: i64, b: i64, x: i64, y: i64,
        h: [i64; n],
    }
    let mut pass = 1 << 30;
    let mut fail = -1;
    while pass - fail > 1 {
        let mid = (pass + fail) / 2;
        let mut hm = h.clone();
        for v in &mut hm {
            *v = max(0, *v - mid);
        }
        if calc(a, b, x, y, &hm) {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    println!("{}", pass);
}
0