結果
問題 |
No.1132 凸凹
|
ユーザー |
|
提出日時 | 2022-01-10 00:50:41 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,372 bytes |
コンパイル時間 | 13,489 ms |
コンパイル使用メモリ | 387,352 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-14 10:38:23 |
合計ジャッジ時間 | 14,802 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
ソースコード
#[macro_export] macro_rules! setup { { mut $input:ident: SplitWhitespace $(,)? } => { use std::io::Read; let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut $input = buf.split_whitespace(); }; } #[macro_export] macro_rules! parse_next { ($str_iter:expr) => { $str_iter.next().unwrap().parse().unwrap() }; } use std::collections::HashMap; fn main() { setup! { mut input: SplitWhitespace }; let a: i64 = parse_next!(input); let b: i64 = parse_next!(input); let c: i64 = parse_next!(input); let d: i64 = parse_next!(input); let p: i64 = parse_next!(input); let q: i64 = parse_next!(input); let f = |x: i64| -> i64 { a * x.pow(3) + b * x.pow(2) + c * x + d }; let mut f_x = HashMap::new(); let mut x_max = p; let mut x_min = p; for x in p..=q { let y = f(x); match x { x if x == p => {} _ => { if *f_x.get(&x_max).unwrap() < y { x_max = x; } if *f_x.get(&x_min).unwrap() > y { x_min = x; } } } f_x.insert(x, y); } let max = *f_x.get(&x_max).unwrap(); let min = *f_x.get(&x_min).unwrap(); println!("{} {} {} {}", max, x_max, min, x_min); }