結果

問題 No.512 魔法少女の追いかけっこ
ユーザー tubo28tubo28
提出日時 2017-05-30 17:42:33
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 5,582 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 143,436 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 13:33:12
合計ジャッジ時間 2,737 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,376 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,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 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,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 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,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 0 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_use]
#[allow(dead_code, unused_macros, non_upper_case_globals)]
mod io {
    macro_rules! p {
        ($x:expr) => {
            println!("{}", $x);
        };
        ($x:expr, $($y:expr),+) => {
            print!("{} ", $x);
            p!($($y),+);
        };
    }

    macro_rules! dump {
        ($($a:expr),+) => {{
            if USE_DUMP {
                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),+);
        };
    }

    pub trait Scan<T> {
        fn scan() -> T;
    }

    macro_rules! scan_primitive {
        ($t: ty) => {
            impl Scan<$t> for $t {
                fn scan() -> $t {
                    get_word().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() -> ( $($t),* ) {
                    ( $( $t::scan()),* )
                }
            }
        };
    }

    scan_primitive!(u8,
                    u16,
                    u32,
                    u64,
                    i8,
                    i16,
                    i32,
                    i64,
                    f32,
                    f64,
                    usize,
                    isize,
                    bool,
                    String);
    scan_tuple!(A, B);
    scan_tuple!(A, B, C);
    scan_tuple!(A, B, C, D);

    pub fn get<T: Scan<T>>() -> T {
        T::scan()
    }

    pub fn get_vec<T: Scan<T>>(n: usize) -> Vec<T> {
        (0..n).map(|_| get()).collect()
    }

    pub fn get_mat<T: Scan<T>>(r: usize, c: usize) -> Vec<Vec<T>> {
        (0..r).map(|_| get_vec(c)).collect()
    }

    pub fn get_vec_char() -> Vec<char> {
        get_word().unwrap().chars().collect()
    }

    pub fn get_mat_char(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| get_vec_char()).collect()
    }

    pub fn get_line() -> String {
        get_line_wrapped().unwrap()
    }

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

    pub fn get_line_wrapped() -> Option<String> {
        let c = get_u8();
        if c.is_none() {
            return None;
        }
        let mut line = String::with_capacity(20);
        line.push(c.unwrap() as char);
        loop {
            let c = 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);
        }
    }

    static mut idx: usize = 0;
    static mut len: usize = 0;
    static mut buf: [u8; 65536] = [0; 65536];

    fn get_u8() -> Option<u8> {
        unsafe {
            use std::io::{stdin, Read};
            if idx == len {
                match stdin().read(&mut buf) {
                    Ok(l) if l > 0 => {
                        idx = 0;
                        len = l;
                    }
                    _ => return None,
                }
            }
            idx += 1;
            Some(buf[idx - 1])
        }
    }

    fn unget_u8(c: u8) {
        unsafe {
            idx -= 1;
            buf[idx] = c;
        }
    }

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

    pub const USE_DUMP: bool = true;
}

use io::*;

fn main() {
    //const EPS: f64 = 1e-9;
    while has_next() {
        let (x, y, n): (i64, i64, _) = get();
        let mut ok = true;
        let mut prev = 0;
        for _ in 0..n {
            let suma = get();
            let a = suma - prev;
            // let t = suma / y;
            // let p = t*x;
            // p < suma - a
            // (suma / y)*x < suma - a
            // suma * x < (suma - a) * y

            // suma - suma * (x/y) > a => false
            // y*suma - x*suma > y*a
            // dump!(y*suma - x*suma, y*a);
            if y*suma - x*suma > y*a {
                ok = false;
            }
            prev = suma;
        }
        p!(if ok { "YES" } else { "NO" });
    }
}
0