結果

問題 No.472 平均順位
ユーザー tubo28tubo28
提出日時 2016-12-28 00:21:03
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 2,316 bytes
コンパイル時間 11,632 ms
コンパイル使用メモリ 378,768 KB
実行使用メモリ 295,936 KB
最終ジャッジ日時 2024-05-08 21:25:56
合計ジャッジ時間 17,762 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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; 5010]; 15010];
        dp[0][0] = 0;
        for i in 0..n {
            let a:i32 = sc.next();
            let b:i32 = sc.next();
            let c:i32 = sc.next();
            for j in 0..(3*n+1) {
                if j >= 0 { dp[i+1][j] = min(dp[i+1][j], dp[i][j-0] + a) }
                if j >= 1 { dp[i+1][j] = min(dp[i+1][j], dp[i][j-1] + b); }
                if j >= 2 { dp[i+1][j] = min(dp[i+1][j], dp[i][j-2] + c) }
                if j >= 3 { dp[i+1][j] = min(dp[i+1][j], dp[i][j-3] + 1) }
            }
        }
        println!("{:.10}", dp[n][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