結果
問題 | No.1739 Princess vs. Dragoness (& AoE) |
ユーザー | koba-e964 |
提出日時 | 2021-11-12 21:46:23 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 270 ms / 3,000 ms |
コード長 | 2,611 bytes |
コンパイル時間 | 1,060 ms |
コンパイル使用メモリ | 158,448 KB |
実行使用メモリ | 4,708 KB |
最終ジャッジ日時 | 2023-08-17 00:47:23 |
合計ジャッジ時間 | 8,243 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 269 ms
4,696 KB |
testcase_05 | AC | 269 ms
4,708 KB |
testcase_06 | AC | 66 ms
4,460 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 143 ms
4,380 KB |
testcase_09 | AC | 233 ms
4,376 KB |
testcase_10 | AC | 94 ms
4,384 KB |
testcase_11 | AC | 69 ms
4,380 KB |
testcase_12 | AC | 6 ms
4,380 KB |
testcase_13 | AC | 165 ms
4,380 KB |
testcase_14 | AC | 190 ms
4,380 KB |
testcase_15 | AC | 268 ms
4,624 KB |
testcase_16 | AC | 66 ms
4,376 KB |
testcase_17 | AC | 127 ms
4,380 KB |
testcase_18 | AC | 119 ms
4,384 KB |
testcase_19 | AC | 98 ms
4,380 KB |
testcase_20 | AC | 53 ms
4,380 KB |
testcase_21 | AC | 207 ms
4,380 KB |
testcase_22 | AC | 238 ms
4,388 KB |
testcase_23 | AC | 269 ms
4,700 KB |
testcase_24 | AC | 268 ms
4,600 KB |
testcase_25 | AC | 268 ms
4,696 KB |
testcase_26 | AC | 270 ms
4,696 KB |
testcase_27 | AC | 265 ms
4,592 KB |
testcase_28 | AC | 268 ms
4,656 KB |
testcase_29 | AC | 269 ms
4,640 KB |
testcase_30 | AC | 268 ms
4,696 KB |
testcase_31 | AC | 268 ms
4,700 KB |
testcase_32 | AC | 268 ms
4,636 KB |
testcase_33 | AC | 1 ms
4,380 KB |
testcase_34 | AC | 1 ms
4,380 KB |
testcase_35 | AC | 1 ms
4,376 KB |
testcase_36 | AC | 1 ms
4,376 KB |
testcase_37 | AC | 1 ms
4,384 KB |
testcase_38 | AC | 2 ms
4,376 KB |
testcase_39 | AC | 3 ms
4,380 KB |
testcase_40 | AC | 2 ms
4,380 KB |
testcase_41 | AC | 2 ms
4,376 KB |
testcase_42 | AC | 1 ms
4,380 KB |
コンパイルメッセージ
warning: unused import: `BufWriter` --> Main.rs:5:22 | 5 | use std::io::{Write, BufWriter}; | ^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `Write` --> Main.rs:5:15 | 5 | use std::io::{Write, BufWriter}; | ^^^^^ warning: 2 warnings emitted
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // 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),* )) => { ($(read_value!($next, $t)),*) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => (read_value!($next, usize) - 1); ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); read_value!($next, [$t; len]) }}; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } 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); }