Skip to content

Commit 105c35f

Browse files
committed
add a wrong answer for abc405d
1 parent 71f1e57 commit 105c35f

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

src/abc/abc405d.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/** THIS IS AN OUTPUT FILE. NOT EDIT THIS FILE DIRECTLY. **/
2+
use proconio::input;
3+
use proconio::marker::*;
4+
use std::marker::PhantomData;
5+
use std::cmp::*;
6+
use std::collections::*;
7+
8+
fn main() {
9+
input! {
10+
h:usize,
11+
w:usize,
12+
rows:[Chars;h],
13+
}
14+
15+
let inf = 1_000_000_000;
16+
let mut dp = vec![vec![inf;w];h];
17+
18+
let mut stack = vec![];
19+
for i in 0..h {
20+
for j in 0..w {
21+
if rows[i][j] == 'E' {
22+
stack.push((i, j));
23+
}
24+
}
25+
}
26+
if stack.is_empty() {
27+
28+
for rows in rows {
29+
println!("{}", rows.iter().collect::<String>());
30+
}
31+
return;
32+
}
33+
34+
dp[stack[0].0][stack[0].1] = 0;
35+
while let Some((i, j)) = stack.pop() {
36+
if i > 0 && dp[i-1][j] > dp[i][j] + 1 && rows[i-1][j] != '#' {
37+
dp[i-1][j] = dp[i][j] + 1;
38+
stack.push((i-1, j));
39+
}
40+
if i < h - 1 && dp[i+1][j] > dp[i][j] + 1 && rows[i+1][j] != '#' {
41+
dp[i+1][j] = dp[i][j] + 1;
42+
stack.push((i+1, j));
43+
}
44+
if j > 0 && dp[i][j-1] > dp[i][j] + 1 && rows[i][j-1] != '#' {
45+
dp[i][j-1] = dp[i][j] + 1;
46+
stack.push((i, j-1));
47+
}
48+
if j < w - 1 && dp[i][j+1] > dp[i][j] + 1 && rows[i][j+1] != '#' {
49+
dp[i][j+1] = dp[i][j] + 1;
50+
stack.push((i, j+1));
51+
}
52+
}
53+
54+
// println!("{:?}", dp);
55+
56+
let mut result = rows.clone();
57+
for i in 0..h {
58+
for j in 0..w {
59+
if result[i][j] != '.' {
60+
continue;
61+
}
62+
63+
let mut stack = vec![(i,j)];
64+
while let Some((i, j)) = stack.pop() {
65+
if i > 0 && result[i-1][j] != '#' && dp[i-1][j] == dp[i][j] - 1 {
66+
result[i][j] = '^';
67+
stack.push((i-1, j));
68+
} else if i < h - 1 && result[i+1][j] != '#' && dp[i+1][j] == dp[i][j] - 1 {
69+
result[i][j] = 'v';
70+
stack.push((i+1, j));
71+
} else if j > 0 && result[i][j-1] != '#' && dp[i][j-1] == dp[i][j] - 1 {
72+
result[i][j] = '<';
73+
stack.push((i, j-1));
74+
} else if j < w - 1 && result[i][j+1] != '#' && dp[i][j+1] == dp[i][j] - 1 {
75+
result[i][j] = '>';
76+
stack.push((i, j+1));
77+
}
78+
}
79+
}
80+
}
81+
82+
for rows in result {
83+
println!("{}", rows.iter().collect::<String>());
84+
}
85+
}

0 commit comments

Comments
 (0)