結果

問題 No.505 カードの数式2
ユーザー tubo28tubo28
提出日時 2017-05-19 16:05:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 6,210 bytes
コンパイル時間 2,865 ms
コンパイル使用メモリ 136,252 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 02:11:03
合計ジャッジ時間 4,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused macro definition: `dump`
   --> Main.rs:141:18
    |
141 |     macro_rules! dump {
    |                  ^^^^
    |
    = note: `#[warn(unused_macros)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#[macro_use]
mod io {
    use std::io::*;

    pub trait Scan<T> {
        fn scan<R: Read>(sc: &mut Scanner<R>) -> T;
    }

    macro_rules! scan_primitive {
        ($t: ty) => {
            impl Scan<$t> for $t {
                fn scan<R: Read>(sc: &mut Scanner<R>) -> $t {
                    sc.next_token().expect("EOF?").parse()
                        .unwrap_or_else(|e| panic!("Cannot parse {}", e))
                }
            }
        };
        ($t: ty, $($u: ty),+) => {
            scan_primitive!($t);
            scan_primitive!($($u),+);
        };
    }

    macro_rules! scan_tuple {
        ($($t: ident),*) => {
            impl< $($t: Scan<$t>),* > Scan< ( $($t),* ) > for ( $($t),* ) {
                fn scan<R: Read>(sc: &mut Scanner<R>) -> ( $($t),* ) {
                    ( $( $t::scan(sc)),* )
                }
            }
        };
    }

    scan_primitive!(u8, u16, u32, u64, i8, i16, i32, i64,
                    f32, f64, usize, isize, bool, String);
    scan_tuple!(T, U);
    scan_tuple!(T, U, V);
    scan_tuple!(T, U, V, W);

    #[allow(dead_code)]
    pub fn cin() -> Scanner<Stdin> {
        Scanner::new(stdin())
    }

    #[allow(dead_code)]
    pub struct Scanner<T> {
        buf: Vec<u8>,
        len: usize,
        idx: usize,
        reader: T,
    }

    #[allow(dead_code)]
    impl<Reader: Read> Scanner<Reader> {
        pub fn new(r: Reader) -> Scanner<Reader> {
            Scanner {
                buf: vec![0; 8192],
                len: 0,
                idx: 0,
                reader: r,
            }
        }

        pub fn next<T: Scan<T>>(&mut self) -> T {
            T::scan::<Reader>(self)
        }

        fn next_token(&mut self) -> Option<String> {
            let mut res = String::with_capacity(16);
            while let Some(c) = self.get_u8() {
                let d = c as char;
                if !d.is_whitespace() {
                    res.push(d);
                } else if res.len() != 0 {
                    self.unget_u8(c);
                    break;
                }
            }
            if res.len() == 0 { None } else { Some(res) }
        }

        pub fn next_line(&mut self) -> String {
            self.next_line_wrapped().unwrap()
        }

        pub fn next_line_wrapped(&mut self) -> Option<String> {
            let c = self.get_u8();
            if c.is_none() {
                return None;
            }
            let mut line = String::with_capacity(20);
            line.push(c.unwrap() as char);
            loop {
                let c = self.get_u8();
                if c.is_none() || c.unwrap() == b'\n' {
                    // コメントはC++等での仕様
                    // if c.is_some() {
                    //     self.unget_u8(b'\n');
                    // }
                    return Some(line);
                }
                line.push(c.unwrap() as char);
            }
        }

        pub fn has_next(&mut self) -> bool {
            loop {
                let c = self.get_u8();
                if c.is_none() {
                    return false;
                }
                let c = c.unwrap();
                if !(c as char).is_whitespace() {
                    self.unget_u8(c);
                    return true;
                }
            }
        }

        fn get_u8(&mut self) -> Option<u8> {
            if self.idx == self.len {
                match self.reader.read(&mut self.buf[..]) {
                    Ok(l) if l > 0 => {
                        self.idx = 0;
                        self.len = l;
                    }
                    _ => return None,
                }
            }
            self.idx += 1;
            Some(self.buf[self.idx - 1])
        }

        fn unget_u8(&mut self, c: u8) {
            self.idx = self.idx - 1;
            self.buf[self.idx] = c;
        }
    }

    // Output
    macro_rules! dump {
        ($($a: expr),+) => {{
            use std::io::*;
            write!(stderr(), "{}:{}\t", file!(), line!()).unwrap();
            dump!(A $($a),+);
            write!(stderr(), " = ").unwrap();
            dump!(B $($a),+);
            writeln!(stderr(), "").unwrap();
        }};
        (A $x: expr) => {
            write!(stderr(), "{}", stringify!($x)).unwrap();
        };
        (A $x: expr, $($y: expr),+) => {
            write!(stderr(), "{}, ", stringify!($x)).unwrap();
            dump!(A $($y),+);
        };
        (B $x: expr) => {
            write!(stderr(), "{:?}", $x).unwrap();
        };
        (B $x: expr, $($y: expr),+) => {
            write!(stderr(), "{:?}, ", $x).unwrap();
            dump!(B $($y),+);
        };
    }

    macro_rules! p {
        ($x:expr) => {
            println!("{:.10}", $x);
        };
        ($x:expr, $($y:expr),+) => {
            print!("{:.10} ", $x);
            p!($($y),+);
        };
    }
}
#[allow(unused_imports)]
use io::*;
use std::*;

fn main() {
    let mut sc = cin();
    while sc.has_next() {
        let n = sc.next();
        let (mut min, mut max) = (0, 0);
        for i in 0..n {
            let a: i64 = sc.next();
            if i == 0 {
                min = a;
                max = a;
            } else {
                //dump!(a);
                let (mut mi, mut ma) = (i64::max_value() / 10, i64::min_value() / 10);
                mi = cmp::min(mi, min*a);
                mi = cmp::min(mi, min+a);
                mi = cmp::min(mi, min-a);
                if a != 0 { mi = cmp::min(mi, min/a); }
                ma = cmp::max(ma, max*a);
                ma = cmp::max(ma, max+a);
                ma = cmp::max(ma, max-a);
                if a != 0 { ma = cmp::max(ma, max/a); }
                mi = cmp::min(mi, max*a);
                mi = cmp::min(mi, max+a);
                mi = cmp::min(mi, max-a);
                if a != 0 { mi = cmp::min(mi, max/a); }
                ma = cmp::max(ma, min*a);
                ma = cmp::max(ma, min+a);
                ma = cmp::max(ma, min-a);
                if a != 0 { ma = cmp::max(ma, min/a); }
                min = mi;
                max = ma;
                //dump!(min, max);
            }
        }
        p!(max);
    }
}
0