結果

問題 No.472 平均順位
ユーザー tubo28tubo28
提出日時 2016-12-28 00:23:36
言語 Rust
(1.77.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 2,335 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 152,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 18:43:06
合計ジャッジ時間 4,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 15 ms
4,376 KB
testcase_10 AC 21 ms
4,376 KB
testcase_11 AC 42 ms
4,376 KB
testcase_12 AC 37 ms
4,380 KB
testcase_13 AC 236 ms
4,380 KB
testcase_14 AC 237 ms
4,376 KB
testcase_15 AC 237 ms
4,376 KB
testcase_16 AC 236 ms
4,380 KB
testcase_17 AC 236 ms
4,380 KB
testcase_18 AC 20 ms
4,376 KB
testcase_19 AC 215 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: comparison is useless due to type limits
  --> Main.rs:15:20
   |
15 |                 if j >= 0 { ndp[j] = min(ndp[j], dp[j-0] + a) }
   |                    ^^^^^^
   |
   = note: `#[warn(unused_comparisons)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn main(){
    let mut sc = Scanner::new();
    use std::cmp::min;
    while !sc.eof() {
        let n = sc.next();
        let p:usize = sc.next();
        let mut dp = [i32::max_value()/2; 15010];
        dp[0] = 0;
        for _ in 0..n {
            let a:i32 = sc.next();
            let b:i32 = sc.next();
            let c:i32 = sc.next();
            let mut ndp = [i32::max_value()/2; 15010];
            for j in 0..(3*n+1) {
                if j >= 0 { ndp[j] = min(ndp[j], dp[j-0] + a) }
                if j >= 1 { ndp[j] = min(ndp[j], dp[j-1] + b); }
                if j >= 2 { ndp[j] = min(ndp[j], dp[j-2] + c) }
                if j >= 3 { ndp[j] = min(ndp[j], dp[j-3] + 1) }
            }
            dp = ndp;
        }
        println!("{:.10}", dp[p] as f64 / n as f64);
    }
}

// Scanner
#[allow(dead_code)]
struct Scanner { token_buffer: Vec<String>, index: usize }

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner { token_buffer: vec![], index: 0 }
    }

    fn next<T>(&mut self) -> T where T: std::str::FromStr {
        self.wrapped::<T>().unwrap()
    }

    fn wrapped<T>(&mut self) -> Option<T> where T: std::str::FromStr {
        match self.get_token() {
            Some(s) => {
                match s.parse::<T>() {
                    Ok(x) => Some(x),
                    Err(_) => None
                }
            },
            None => None
        }
    }

    fn eof(&mut self) -> bool {
        if !self.read_line() {
            true
        } else {
            self.index >= self.token_buffer.len()
        }
    }

    fn get_token(&mut self) -> Option<&String> {
        if !self.read_line() {
            None
        } else {
            self.index += 1;
            Some(&self.token_buffer[self.index - 1])
        }
    }

    fn read_line(&mut self) -> bool {
        while self.index >= self.token_buffer.len() {
            let mut st = String::new();
            while st.trim() == "" {
                match std::io::stdin().read_line(&mut st) {
                    Ok(l) if l > 0 => continue,
                    _ => return false
                }
            }
            self.token_buffer = st.split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.index = 0;
        }
        true
    }
}
0