結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-03 01:20:17 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1,417 ms / 3,000 ms |
| コード長 | 1,961 bytes |
| コンパイル時間 | 14,511 ms |
| コンパイル使用メモリ | 377,912 KB |
| 実行使用メモリ | 37,632 KB |
| 最終ジャッジ日時 | 2024-11-16 09:06:36 |
| 合計ジャッジ時間 | 28,535 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
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!();
}