結果

問題 No.2064 Smallest Sequence on Grid
ユーザー phsplsphspls
提出日時 2022-09-03 01:20:17
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,306 ms / 3,000 ms
コード長 1,961 bytes
コンパイル時間 21,392 ms
コンパイル使用メモリ 377,328 KB
実行使用メモリ 37,632 KB
最終ジャッジ日時 2024-04-28 01:11:34
合計ジャッジ時間 25,229 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 136 ms
37,248 KB
testcase_18 AC 58 ms
37,248 KB
testcase_19 AC 120 ms
37,248 KB
testcase_20 AC 878 ms
37,632 KB
testcase_21 AC 994 ms
37,504 KB
testcase_22 AC 618 ms
37,504 KB
testcase_23 AC 650 ms
37,504 KB
testcase_24 AC 640 ms
37,632 KB
testcase_25 AC 635 ms
37,504 KB
testcase_26 AC 1,265 ms
37,504 KB
testcase_27 AC 1,306 ms
37,504 KB
testcase_28 AC 40 ms
37,248 KB
testcase_29 AC 1,039 ms
31,872 KB
testcase_30 AC 38 ms
34,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashSet;

fn main() {
    let mut hw = String::new();
    std::io::stdin().read_line(&mut hw).ok();
    let hw: Vec<usize> = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let h = hw[0];
    let w = hw[1];
    let grid = (0..h).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp = temp.trim();
            temp.chars().collect::<Vec<char>>()
        })
        .collect::<Vec<Vec<char>>>();

    let mut result = vec![];
    let mut fronts = HashSet::new();
    result.push(grid[0][0]);
    fronts.insert((0, 0));
    for _ in 0..h+w-2 {
        let mut nexts = HashSet::new();
        let mut candc = None;
        for &(x, y) in fronts.iter() {
            if x + 1 < h {
                if candc.is_none() {
                    candc = Some(grid[x+1][y]);
                    nexts.insert((x+1, y));
                } else if candc.unwrap() as usize > grid[x+1][y] as usize {
                    candc = Some(grid[x+1][y]);
                    nexts = HashSet::new();
                    nexts.insert((x+1, y));
                } else if candc.unwrap() as usize == grid[x+1][y] as usize {
                    nexts.insert((x+1, y));
                }
            }
            if y + 1 < w {
                if candc.is_none() {
                    candc = Some(grid[x][y+1]);
                    nexts.insert((x, y+1));
                } else if candc.unwrap() as usize > grid[x][y+1] as usize {
                    candc = Some(grid[x][y+1]);
                    nexts = HashSet::new();
                    nexts.insert((x, y+1));
                } else if candc.unwrap() as usize == grid[x][y+1] as usize {
                    nexts.insert((x, y+1));
                }
            }
        }
        result.push(candc.unwrap());
        fronts = nexts;
    }
    for c in result.into_iter() { print!("{}", c); }
    println!();
}
0