Please sign in first.
Submission #49004637
Source Code Expand
use proconio::{input, marker::Chars};
fn main() {
input! {
n: usize,
m: usize,
a: [Chars; n],
};
let mut b = vec![vec![]; 11];
for i in 0..n {
for j in 0..m {
match a[i][j] {
'S' => {
b[0] = vec![(i, j)];
}
'G' => {
b[10] = vec![(i, j)];
}
_ => {
b[(a[i][j] as u8 - b'0') as usize].push((i, j));
}
}
}
}
let inf = 1_000_000_000_i64;
let mut dist = vec![vec![inf; m]; n];
dist[b[0][0].0][b[0][0].1] = 0;
for i in 1..=10 {
let mut next = vec![vec![inf; m]; n];
for (pr, pc) in b[i - 1].iter().copied() {
let pd = dist[pr][pc];
for (nr, nc) in b[i].iter().copied() {
let nd = pd + (pr as i64 - nr as i64).abs() + (pc as i64 - nc as i64).abs();
next[nr][nc] = next[nr][nc].min(nd);
}
}
dist = next;
}
let ans = dist[b[10][0].0][b[10][0].1];
let ans = if ans == inf { -1 } else { ans };
println!("{}", ans);
}
Submission Info
| Submission Time | |
|---|---|
| Task | H - 1-9 Grid |
| User | bouzuya |
| Language | Rust (rustc 1.70.0) |
| Score | 6 |
| Code Size | 1181 Byte |
| Status | AC |
| Exec Time | 2 ms |
| Memory | 2184 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 6 / 6 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| 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, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 1 ms | 1908 KiB |
| 02.txt | AC | 1 ms | 1924 KiB |
| 03.txt | AC | 1 ms | 1960 KiB |
| 04.txt | AC | 1 ms | 2076 KiB |
| 05.txt | AC | 1 ms | 2080 KiB |
| 06.txt | AC | 1 ms | 1868 KiB |
| 07.txt | AC | 1 ms | 1892 KiB |
| 08.txt | AC | 1 ms | 2056 KiB |
| 09.txt | AC | 1 ms | 2092 KiB |
| 10.txt | AC | 1 ms | 1912 KiB |
| 11.txt | AC | 1 ms | 2012 KiB |
| 12.txt | AC | 2 ms | 2116 KiB |
| 13.txt | AC | 2 ms | 2084 KiB |
| 14.txt | AC | 1 ms | 2044 KiB |
| 15.txt | AC | 2 ms | 2108 KiB |
| 16.txt | AC | 1 ms | 2184 KiB |
| 17.txt | AC | 2 ms | 2124 KiB |
| 18.txt | AC | 1 ms | 2032 KiB |
| 19.txt | AC | 2 ms | 1984 KiB |
| 20.txt | AC | 1 ms | 2028 KiB |
| 21.txt | AC | 1 ms | 2068 KiB |
| 22.txt | AC | 1 ms | 1872 KiB |
| 23.txt | AC | 1 ms | 1936 KiB |
| 24.txt | AC | 1 ms | 1940 KiB |
| 25.txt | AC | 1 ms | 1976 KiB |
| 26.txt | AC | 1 ms | 1916 KiB |
| 27.txt | AC | 1 ms | 1936 KiB |
| 28.txt | AC | 1 ms | 2100 KiB |
| 29.txt | AC | 2 ms | 2012 KiB |
| 30.txt | AC | 1 ms | 2052 KiB |
| 31.txt | AC | 1 ms | 2028 KiB |
| 32.txt | AC | 1 ms | 2036 KiB |
| 33.txt | AC | 1 ms | 2016 KiB |
| 34.txt | AC | 1 ms | 1948 KiB |
| 35.txt | AC | 1 ms | 1996 KiB |
| 36.txt | AC | 1 ms | 1928 KiB |
| s1.txt | AC | 1 ms | 1968 KiB |
| s2.txt | AC | 1 ms | 2076 KiB |
| s3.txt | AC | 1 ms | 2080 KiB |