| Task: | Hypyt |
| Sender: | wolruso |
| Submission time: | 2025-11-08 11:19:23 +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 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #2 | WRONG ANSWER | 0.01 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 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #6 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
| #7 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
| #8 | TIME LIMIT EXCEEDED | -- | 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 | ACCEPTED | 0.37 s | 5 | details |
| #22 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #23 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #24 | WRONG ANSWER | 0.56 s | 5 | details |
| #25 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #26 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #27 | ACCEPTED | 0.33 s | 5 | details |
Code
use std::{collections::HashMap, io::stdin};
fn q_itr(q: usize) -> impl Iterator<Item = (usize, usize, usize, usize)> {
(0..q).map(|_| {
let mut ln = String::new();
stdin().read_line(&mut ln).unwrap();
let mut litr = ln.split_ascii_whitespace();
let y1 = litr.next().unwrap().parse::<usize>().unwrap() - 1;
let x1 = litr.next().unwrap().parse::<usize>().unwrap() - 1;
let y2 = litr.next().unwrap().parse::<usize>().unwrap() - 1;
let x2 = litr.next().unwrap().trim_end().parse::<usize>().unwrap() - 1;
(x1, y1, x2, y2)
})
}
fn main() {
let mut l = String::new();
stdin().read_line(&mut l).unwrap();
let mut itr = l.split_ascii_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
let m: usize = itr.next().unwrap().parse().unwrap();
let q: usize = itr.next().unwrap().trim_end().parse().unwrap();
let mut sr: Vec<Vec<usize>> = Vec::with_capacity(n);
let mut sc: Vec<Vec<usize>> = Vec::with_capacity(m);
for _ in 0..n {
sr.push(Vec::new());
}
for _ in 0..m {
sc.push(Vec::new());
}
for i in 0..n {
let mut ln = String::new();
stdin().read_line(&mut ln).unwrap();
for (j, c) in ln.chars().enumerate() {
if c == '.' {
sr[i].push(j);
sc[j].push(i);
}
}
}
let mut alr_vis = Vec::with_capacity(m);
for _ in 0..m {
let mut v = Vec::with_capacity(n);
for _ in 0..n {
v.push(false);
}
alr_vis.push(v);
}
// let queries: Vec<(usize, usize, usize, usize)> = q_itr(q).collect();
// let q_in_order = queries.clone();
// queries.sort_unstable();
let mut results = HashMap::with_capacity(q);
for ref qry in q_itr(q) {
if !results.contains_key(qry) {
let r = p_recur(
qry.0,
qry.1,
qry.2,
qry.3,
&sc,
&sr,
alr_vis.clone(),
&mut results,
);
results.insert(*qry, r);
}
println!("{}", results[qry]);
}
}
/*
* Problem:
* State: S(x,y)
* Goal: S(x, y) = G(x2, y2)
* Available options at S(x,y) = N(x,y)
* Task: Find the path P(S1, S2, S3, ..., SN) with the minimum N
*
* Additional properties:
* Property One: If S1 in S2N then S2 in S1N -> undirected graph, with Sk as the nodes
* Property Two: SkN divided into two sets: one where x = Sk.x and the other where y = Sk.y
* Property Three: Up to 2 * 10^5 queries made simultaneoously, instead of only one. I.e, need to
* make heavy use of previous results.
*
* Possible solutions:
* 1. Trivial algorithm for finding minimum path between two nodes in a given graph
* 2. Well-known and more optimal algorithm for finding minimum path between two nodes in a given
* graph
* 3. Hand-crafted algorithm also making use of the second property
* */
fn p_recur(
x: usize,
y: usize,
x2: usize,
y2: usize,
sc: &[Vec<usize>],
sr: &[Vec<usize>],
mut alr_vis: Vec<Vec<bool>>,
s_paths: &mut HashMap<(usize, usize, usize, usize), isize>,
) -> isize {
if alr_vis[x][y] {
return -1;
}
alr_vis[x][y] = true;
if x == x2 && y == y2 {
return 0;
}
let q = (x, y, x2, y2);
if s_paths.contains_key(&q) {
if s_paths[&q] == -1 {
return -1;
} else {
return s_paths[&q];
}
}
let mut m = -1;
for xn in &sr[y] {
if *xn == x {
continue;
}
let r = p_recur(*xn, y, x2, y2, sc, sr, alr_vis.clone(), s_paths);
let qn = (*xn, y, x2, y2);
s_paths.insert(qn, r);
if r != -1 && (m == -1 || r < m) {
m = r;
if m <= 1 {
return m + 1;
}
}
}
for yn in &sc[x] {
if *yn == y {
continue;
}
let r = p_recur(x, *yn, x2, y2, sc, sr, alr_vis.clone(), s_paths);
let qn = (x, *yn, x2, y2);
s_paths.insert(qn, r);
if r != -1 && (m == -1 || r < m) {
m = r;
if m <= 1 {
return m + 1;
}
}
}
return m + 1;
}
Test details
Test 1 (public)
Group: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 4 6 5 .*.*** *...** *****. *..*.* ... |
| correct output |
|---|
| 1 0 3 3 -1 |
| user output |
|---|
| 1 0 4 3 0 |
Feedback: Incorrect character on line 3 col 1: expected "3", got "4"
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 3 2 3 3 ... |
Feedback: Incorrect character on line 2 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 |
|---|
| 2 3 3 2 3 ... |
Feedback: Incorrect character on line 1 col 1: expected "1", got "2"
Test 4
Group: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 10 ***.*.**** ********** *.******** .*.***.**. ... |
| correct output |
|---|
| 3 4 2 3 4 ... |
| user output |
|---|
| 3 4 2 2 4 ... |
Feedback: Incorrect character on line 4 col 1: expected "3", got "2"
Test 5
Group: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 1 .****.**** **.**..*** ********** *******..* ... |
| correct output |
|---|
| 7 |
| user output |
|---|
| 3 |
Feedback: Incorrect character on line 1 col 1: expected "7", got "3"
Test 6
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 .*...*.....*******..**...*....... |
| correct output |
|---|
| 2 3 3 2 2 ... |
| user output |
|---|
| (empty) |
Test 7
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 ...*......**.**.*.*..**..*..**... |
| correct output |
|---|
| 2 2 2 2 3 ... |
| user output |
|---|
| (empty) |
Test 8
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 **..**..****.****.*.***.***..*... |
| correct output |
|---|
| 2 3 3 3 3 ... |
| user output |
|---|
| (empty) |
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: ACCEPTED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 498 498 498 498 498 ... |
| user output |
|---|
| 498 498 498 498 498 ... |
Test 22
Group: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 1 10 * * . * ... |
| correct output |
|---|
| 0 1 1 0 0 ... |
| user output |
|---|
| 0 1 1 0 0 ... |
Feedback: Incorrect character on line 6 col 1: expected "1", got "2"
Test 23
Group: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| 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 |
|---|
| 2 2 1 2 2 ... |
Feedback: Incorrect character on line 1 col 1: expected "1", got "2"
Test 24
Group: 5
Verdict: WRONG ANSWER
| input |
|---|
| 250 1 200000 * . * . ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 2 2 2 2 2 ... |
Feedback: Incorrect character on line 1 col 1: expected "1", got "2"
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 ... |
