提出 #18833569


ソースコード 拡げる

use std::cmp::max;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let h: usize = sc.read();
    let w: usize = sc.read();
    let k: usize = sc.read();
    let mut map = vec![vec![0; w]; h];
    for _ in 0..k {
        let r = sc.read::<usize>() - 1;
        let c = sc.read::<usize>() - 1;
        let v = sc.read::<i64>();
        map[r][c] = v;
    }

    let mut dp = vec![vec![0; 4]; w];
    for i in 0..h {
        let mut next_dp = vec![vec![0; 4]; w];
        for j in 0..w {
            for cur in (0..3).rev() {
                dp[j][cur + 1] = max(dp[j][cur + 1], dp[j][cur] + map[i][j]);
            }
            for cur in 0..4 {
                if j + 1 < w {
                    dp[j + 1][cur] = max(dp[j + 1][cur], dp[j][cur]);
                }
                next_dp[j][0] = max(next_dp[j][0], dp[j][cur]);
            }
        }

        if i + 1 < h {
            dp = next_dp;
        }
    }
    println!("{}", *dp[w - 1].iter().max().unwrap());
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

提出情報

提出日時
問題 E - Picking Goods
ユーザ kenkoooo
言語 Rust (1.42.0)
得点 500
コード長 2218 Byte
結果 AC
実行時間 594 ms
メモリ 72876 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 37
セット名 テストケース
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, s1.txt, s2.txt, s3.txt
ケース名 結果 実行時間 メモリ
01.txt AC 1 ms 2076 KiB
02.txt AC 2 ms 1940 KiB
03.txt AC 1 ms 2168 KiB
04.txt AC 1 ms 2140 KiB
05.txt AC 5 ms 1940 KiB
06.txt AC 3 ms 2092 KiB
07.txt AC 1 ms 2108 KiB
08.txt AC 2 ms 2084 KiB
09.txt AC 5 ms 2076 KiB
10.txt AC 2 ms 1976 KiB
11.txt AC 1 ms 2048 KiB
12.txt AC 585 ms 72876 KiB
13.txt AC 587 ms 72732 KiB
14.txt AC 594 ms 72704 KiB
15.txt AC 585 ms 72436 KiB
16.txt AC 591 ms 72768 KiB
17.txt AC 485 ms 72556 KiB
18.txt AC 491 ms 72760 KiB
19.txt AC 484 ms 72596 KiB
20.txt AC 484 ms 72596 KiB
21.txt AC 570 ms 72688 KiB
22.txt AC 563 ms 72820 KiB
23.txt AC 32 ms 2540 KiB
24.txt AC 35 ms 2924 KiB
25.txt AC 12 ms 2260 KiB
26.txt AC 5 ms 2488 KiB
27.txt AC 70 ms 3380 KiB
28.txt AC 55 ms 3540 KiB
29.txt AC 520 ms 72752 KiB
30.txt AC 569 ms 72556 KiB
31.txt AC 509 ms 72652 KiB
32.txt AC 505 ms 72536 KiB
33.txt AC 518 ms 72728 KiB
34.txt AC 535 ms 72684 KiB
s1.txt AC 1 ms 1968 KiB
s2.txt AC 1 ms 2088 KiB
s3.txt AC 1 ms 2116 KiB