結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー tanzakutanzaku
提出日時 2017-03-24 22:49:02
言語 Rust
(1.72.1)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,359 bytes
コンパイル時間 7,133 ms
コンパイル使用メモリ 143,968 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 01:54:37
合計ジャッジ時間 2,321 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


fn main() {
    let mut scanner = Scanner::new();
    let gx = scanner.next_usize();
    let gy = scanner.next_usize();
    let n = scanner.next_usize();
    let f = scanner.next_usize();
    let mut x = Vec::new();
    let mut y = Vec::new();
    let mut c = Vec::new();
    for _ in 0..n {
        x.push(scanner.next_usize());
        y.push(scanner.next_usize());
        c.push(scanner.next_usize());
    }
    let inf = 1_000000000_000000000_usize;
    let mut ans = vec![vec![inf; gx+1]; gy+1];
    ans[0][0] = 0;
    for k in 0..n {
        for i in 0..(gy+1) {
            for j in 0..gx+1 {
                let i = gy - i;
                let j = gx - j;
                if x[k] <= j && y[k] <= i {
                    ans[i][j] = std::cmp::min(ans[i][j], ans[i-y[k]][j-x[k]] + c[k])
                }
            }
        }
    }
    let mut res = std::usize::MAX;
    for i in 0..(gy+1) {
        for j in 0..gx+1 {
            res = std::cmp::min(res, ans[i][j] + ((gy-i)+(gx-j))*f);
        }
    }
    println!("{}", res);
}


struct Scanner {
    reader: std::io::Stdin,
    tokens: std::collections::VecDeque<String>,
}

impl Scanner {
    fn new() -> Self {
        Scanner {
            reader: std::io::stdin(),
            tokens: std::collections::VecDeque::new(),
        }
    }

    fn next(&mut self) -> String {
        if self.tokens.is_empty() {
        let mut s = String::new();
            loop {
                self.reader.read_line(&mut s).ok();
                let s = s.trim();
                if s.len() != 0 {
                    for it in s.split_whitespace() {
                        self.tokens.push_back(it.into())
                    }
                    break;
                }
            }
        }
        self.tokens.pop_front().unwrap()
    }

    fn next_generics<T>(&mut self) -> T where
        T: std::str::FromStr + std::marker::Copy,
        <T as std::str::FromStr>::Err: std::fmt::Debug
    {
        self.next().parse().unwrap()
    }
    
    #[allow(dead_code)] fn next_i32(&mut self) -> i32 { self.next_generics::<i32>() }
    #[allow(dead_code)] fn next_i64(&mut self) -> i64 { self.next_generics::<i64>() }
    #[allow(dead_code)] fn next_u64(&mut self) -> u64 { self.next_generics::<u64>() }
    #[allow(dead_code)] fn next_usize(&mut self) -> usize { self.next_generics::<usize>() }
}

0