| Task: | Hypyt |
| Sender: | JuusoH |
| Submission time: | 2025-10-30 17:10:46 +0200 |
| Language: | Rust (2021) |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| #4 | WRONG ANSWER | 0 |
| #5 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #2 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #3 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #4 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #6 | WRONG ANSWER | 0.08 s | 2, 5 | details |
| #7 | WRONG ANSWER | 0.06 s | 2, 5 | details |
| #8 | WRONG ANSWER | 0.05 s | 2, 5 | details |
| #9 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #10 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #13 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #14 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #16 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #17 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #18 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #19 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #20 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #21 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #22 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #23 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #24 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #25 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #26 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #27 | ACCEPTED | 0.35 s | 5 | details |
Code
use std::cmp::Ordering;
use std::{
collections::{BinaryHeap, HashMap},
io,
};
type Pos = (usize, usize);
fn main() {
let mut input = String::new();
let stdin = io::stdin();
_ = stdin.read_line(&mut input);
let mut first_line = input.split_whitespace();
let n: usize = first_line.next().unwrap().parse().unwrap();
let m: usize = first_line.next().unwrap().parse().unwrap();
let q: usize = first_line.next().unwrap().parse().unwrap();
let mut board: Vec<Vec<bool>> = vec![];
for _ in 0..n {
input.clear();
_ = stdin.read_line(&mut input);
let mut line = input.chars();
let mut vec = vec![];
for _ in 0..m {
vec.push(line.next().unwrap() == '*');
}
board.push(vec);
}
let mut tests: Vec<(usize, usize, usize, usize)> = vec![];
for _ in 0..q {
input.clear();
_ = stdin.read_line(&mut input);
let mut line = input.split_whitespace();
let y1: usize = line.next().unwrap().parse().unwrap();
let x1: usize = line.next().unwrap().parse().unwrap();
let y2: usize = line.next().unwrap().parse().unwrap();
let x2: usize = line.next().unwrap().parse().unwrap();
tests.push((y1 - 1, x1 - 1, y2 - 1, x2 - 1));
}
for t in tests {
let start = (t.0, t.1);
let end = (t.2, t.3);
println!("{}", a_star(&board, start, end).len() as i32 - 1);
}
}
fn a_star(board: &Vec<Vec<bool>>, start: Pos, end: Pos) -> Vec<Pos> {
let mut open_set: BinaryHeap<AStarTile> = BinaryHeap::from([AStarTile {
cost: 0,
position: start,
}]);
let mut came_from: HashMap<Pos, Pos> = HashMap::new();
let mut g_score: HashMap<Pos, usize> = HashMap::new();
g_score.insert(start, 0);
let mut f_score: HashMap<Pos, usize> = HashMap::new();
f_score.insert(start, heuristic(start, end));
while open_set.len() > 0 {
let current: Pos = open_set.pop().unwrap().position;
if current == end {
return get_res_path(&came_from, current);
}
for neighbor in get_neighbors(¤t, &board) {
let tentative_score = g_score.get(¤t).unwrap_or(&usize::MAX) + 1;
if tentative_score < *g_score.get(&neighbor).unwrap_or(&usize::MAX) {
came_from.insert(neighbor, current);
g_score.insert(neighbor, tentative_score);
let score_f = tentative_score + heuristic(neighbor, end);
f_score.insert(neighbor, score_f);
open_set.push(AStarTile {
cost: score_f,
position: neighbor,
});
}
}
}
return vec![]; //no path found
}
fn get_neighbors(pos: &Pos, board: &Vec<Vec<bool>>) -> Vec<Pos> {
let mut res: Vec<Pos> = vec![];
let n = board.len();
let m = board[0].len();
for i in 0..n {
if i == pos.0 {
continue;
}
if !board[i][pos.1] {
res.push((i, pos.1));
}
}
for i in 0..m {
if i == pos.1 {
continue;
}
if !board[pos.0][i] {
res.push((pos.0, i));
}
}
res
}
fn get_res_path(came_from: &HashMap<Pos, Pos>, mut current: Pos) -> Vec<Pos> {
let mut res: Vec<Pos> = vec![current];
loop {
if let Some(prev) = came_from.get(¤t) {
current = *prev;
res.push(current);
} else {
break;
}
}
res.reverse();
res
}
fn heuristic(start: Pos, end: Pos) -> usize {
start.0.abs_diff(end.0) + start.1.abs_diff(end.1)
}
#[derive(Copy, Clone, Eq, PartialEq)]
struct AStarTile {
cost: usize,
position: Pos,
}
impl PartialOrd for AStarTile {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for AStarTile {
fn cmp(&self, other: &Self) -> Ordering {
other
.cost
.cmp(&self.cost)
.then_with(|| self.position.cmp(&other.position))
}
}
Test details
Test 1 (public)
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 4 6 5 .*.*** *...** *****. *..*.* ... |
| correct output |
|---|
| 1 0 3 3 -1 |
| user output |
|---|
| 1 0 3 3 -1 |
Test 2
Group: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 10 .......... .....*.... ........*. *.*....*.. ... |
| correct output |
|---|
| 1 2 1 2 2 ... |
| user output |
|---|
| 1 2 1 2 3 ... |
Feedback: Incorrect character on line 5 col 1: expected "2", got "3"
Test 3
Group: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 10 *...***.** *****.*... **..**.**. ..**.**.*. ... |
| correct output |
|---|
| 1 2 2 1 2 ... |
| user output |
|---|
| 1 2 3 1 2 ... |
Feedback: Incorrect character on line 3 col 1: expected "2", got "3"
Test 4
Group: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 10 ***.*.**** ********** *.******** .*.***.**. ... |
| correct output |
|---|
| 3 4 2 3 4 ... |
| user output |
|---|
| 7 4 5 5 5 ... |
Feedback: Incorrect character on line 1 col 1: expected "3", got "7"
Test 5
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 1 .****.**** **.**..*** ********** *******..* ... |
| correct output |
|---|
| 7 |
| user output |
|---|
| 7 |
Test 6
Group: 2, 5
Verdict: WRONG ANSWER
| input |
|---|
| 250 250 250 .*...*.....*******..**...*....... |
| correct output |
|---|
| 2 3 3 2 2 ... |
| user output |
|---|
| 2 3 4 4 3 ... |
Feedback: Incorrect character on line 3 col 1: expected "3", got "4"
Test 7
Group: 2, 5
Verdict: WRONG ANSWER
| input |
|---|
| 250 250 250 ...*......**.**.*.*..**..*..**... |
| correct output |
|---|
| 2 2 2 2 3 ... |
| user output |
|---|
| 2 2 2 2 5 ... |
Feedback: Incorrect character on line 5 col 1: expected "3", got "5"
Test 8
Group: 2, 5
Verdict: WRONG ANSWER
| input |
|---|
| 250 250 250 **..**..****.****.*.***.***..*... |
| correct output |
|---|
| 2 3 3 3 3 ... |
| user output |
|---|
| 4 3 6 5 5 ... |
Feedback: Incorrect character on line 1 col 1: expected "2", got "4"
Test 9
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 ...*.**.*..*.............*.*..... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 10
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 **.**..*.*.*.******....****.*.... |
| correct output |
|---|
| 2 1 3 2 2 ... |
| user output |
|---|
| (empty) |
Test 11
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 .*.*.**.*****.***.*.****.**.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 12
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *....**.***..****...*.....*...... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 13
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 .***.*..*.***..*****....**...*... |
| correct output |
|---|
| 3 2 2 3 2 ... |
| user output |
|---|
| (empty) |
Test 14
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *******.*****.*..*..****...***... |
| correct output |
|---|
| 2 3 1 2 2 ... |
| user output |
|---|
| (empty) |
Test 15
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *....*..*..*..**..*.........**... |
| correct output |
|---|
| 3 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 16
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..*....*..*......*.**.*.*..***... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 17
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *..*.*****.*********.****.****... |
| correct output |
|---|
| 3 3 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 18
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *********.**********.******.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 19
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 104 422 145 93 65 ... |
| user output |
|---|
| (empty) |
Test 20
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..****************************... |
| correct output |
|---|
| 57 155 38 65 98 ... |
| user output |
|---|
| (empty) |
Test 21
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 498 498 498 498 498 ... |
| user output |
|---|
| (empty) |
Test 22
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 1 10 * * . * ... |
| correct output |
|---|
| 0 1 1 0 0 ... |
| user output |
|---|
| 0 1 1 0 0 ... |
Test 23
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 1 10 10 ........*. 1 7 1 10 1 4 1 7 1 5 1 1 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 ... |
Test 24
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 1 200000 * . * . ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 25
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 1 250 200000 *.*.*...*.*.**.***..**.*.*..**... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 26
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ................................. |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 27
Group: 5
Verdict: ACCEPTED
| input |
|---|
| 250 250 200000 ******************************... |
| correct output |
|---|
| 0 0 0 0 0 ... |
| user output |
|---|
| 0 0 0 0 0 ... |
