| Task: | Ratsun reitit |
| Sender: | jkan |
| Submission time: | 2020-10-04 22:16:58 +0300 |
| Language: | Rust |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
| #3 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
| #4 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
| #5 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
| #6 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
| #7 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
| #8 | WRONG ANSWER | 0.01 s | 2, 3 | details |
| #9 | WRONG ANSWER | 0.01 s | 2, 3 | details |
| #10 | WRONG ANSWER | 0.01 s | 2, 3 | details |
| #11 | WRONG ANSWER | 0.04 s | 3 | details |
| #12 | WRONG ANSWER | 0.09 s | 3 | details |
| #13 | WRONG ANSWER | 0.09 s | 3 | details |
Code
use std::io::{BufRead, BufReader};
fn pretty_print_matrix(m: Vec<Vec<Option<i32>>>) -> String {
m.iter()
.map(|v|{
v.iter()
.map(|i|{
match i {
None => "X".to_string(),
Some(i) => i.to_string(),
}
})
.fold("".to_string(), |acc, el| {
match acc.len() {
0 => el,
_ => format!("{} {}", acc, el)
}
})
})
.fold("".to_string(), |acc,el| {
match acc.len() {
0 => el,
_ => format!("{}{}{}", acc, '\n', el)
}
})
}
#[derive(PartialEq, Copy, Clone, Debug)]
struct Move(i32, i32);
impl Eq for Move {}
fn chained_comp(b: i32,v: i32,a: i32) -> bool {
b < v && v < a
}
fn recurse_knight_moves(
board: &mut Vec<Vec<Option<i32>>>,
pos: Move,
depth: i32,
note: &mut Vec<Move>) {
if note.contains(&pos) {
return ();
}
let mut moves = vec![
Move(-2,-1),
Move(-1,-2),
Move(1,-2),
Move(2, -1),
Move(2,1),
Move(1,2),
Move(-1,2),
Move(-2,1),
];
let bsize = board.len() as i32;
moves = moves.iter()
.map(|t|{Move(t.0+pos.0, t.1+pos.1)})
.filter(|t|{chained_comp(-1,t.0,bsize) && chained_comp(-1,t.1,bsize)})
// // .filter(|t|{!note.contains(t)})
.collect::<Vec<Move>>();
let mut done = Vec::new();
for t in moves {
let v = board[t.0 as usize][t.1 as usize];
if v.unwrap_or(9999) > depth {
board[t.0 as usize][t.1 as usize] = Some(depth);
done.push(t)
}
}
// println!("{}\n",pretty_print_matrix(board.clone()));
note.push(pos);
for t in done {
recurse_knight_moves(board, t, depth+1, note);
}
}
fn main() {
let mut input = BufReader::new(std::io::stdin());
let mut line = "".to_string();
input.read_line(&mut line).unwrap();
line.pop();
let n: i32 = line.parse().unwrap();
let mut board = Vec::new();
for _ in 0..n {
let mut tmp = Vec::new();
for _ in 0..n {
tmp.push(None)
}
board.push(tmp)
}
board[0][0] = Some(0);
let mut note = Vec::new();
recurse_knight_moves(&mut board,Move(0,0),1,&mut note);
println!("{}",pretty_print_matrix(board));
}
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 4 |
| correct output |
|---|
| 0 3 2 5 3 4 1 2 2 1 4 3 5 2 3 2 |
| user output |
|---|
| 0 3 2 5 3 4 1 2 2 1 4 3 5 2 3 2 |
Test 2
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 5 |
| correct output |
|---|
| 0 3 2 3 2 3 4 1 2 3 2 1 4 3 2 3 2 3 2 3 2 3 2 3 4 |
| user output |
|---|
| 0 3 2 5 2 3 4 1 2 3 2 1 6 3 2 3 2 3 2 3 2 3 2 5 4 |
Test 3
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 6 |
| correct output |
|---|
| 0 3 2 3 2 3 3 4 1 2 3 4 2 1 4 3 2 3 3 2 3 2 3 4 2 3 2 3 4 3 ... |
| user output |
|---|
| 0 3 2 7 2 3 3 4 1 2 3 6 2 1 6 3 2 3 3 2 3 2 3 6 2 3 2 5 4 3 ... |
Test 4
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 7 |
| correct output |
|---|
| 0 3 2 3 2 3 4 3 4 1 2 3 4 3 2 1 4 3 2 3 4 3 2 3 2 3 4 3 2 3 2 3 4 3 4 ... |
| user output |
|---|
| 0 3 2 7 2 3 20 3 4 1 2 3 6 11 2 1 6 3 2 3 6 3 2 3 2 3 8 11 2 3 2 7 4 3 6 ... Truncated |
Test 5
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 8 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 3 4 1 2 3 4 3 4 2 1 4 3 2 3 4 5 3 2 3 2 3 4 3 4 2 3 2 3 4 3 4 5 ... |
| user output |
|---|
| 0 3 2 9 2 3 8 9 3 4 1 2 3 8 9 8 2 1 10 3 2 3 16 7 3 2 3 2 3 6 7 8 2 3 2 9 4 3 6 9 ... Truncated |
Test 6
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 9 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 4 3 4 1 2 3 4 3 4 5 2 1 4 3 2 3 4 5 4 3 2 3 2 3 4 3 4 5 2 3 2 3 4 3 4 5 4 ... |
| user output |
|---|
| 0 3 2 9 2 3 10 19 20 3 4 1 2 3 10 17 20 19 2 1 8 3 2 3 10 17 18 3 2 3 2 3 8 19 16 17 2 3 2 ... Truncated |
Test 7
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 4 5 3 4 1 2 3 4 3 4 5 6 2 1 4 3 2 3 4 5 4 5 3 2 3 2 3 4 3 4 5 6 2 3 2 3 4 3 4 5 4 5 ... |
| user output |
|---|
| 0 3 2 11 2 3 12 15 28 25 3 4 1 2 3 12 15 16 25 26 2 1 10 3 2 3 12 15 16 27 3 2 3 2 3 10 15 ... Truncated |
Test 8
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 25 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
| user output |
|---|
| 0 3 2 25 2 3 26 65 66 67 70 69... Truncated |
Test 9
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 49 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
| user output |
|---|
| 0 3 2 49 2 3 50 125 126 127 13... Truncated |
Test 10
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 50 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
| user output |
|---|
| 0 3 2 51 2 3 52 123 124 125 12... Truncated |
Test 11
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 75 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
| user output |
|---|
| 0 3 2 75 2 3 76 189 186 187 19... Truncated |
Test 12
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 99 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
| user output |
|---|
| 0 3 2 99 2 3 100 249 246 247 2... Truncated |
Test 13
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 100 |
| correct output |
|---|
| 0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
| user output |
|---|
| 0 3 2 101 2 3 102 253 250 251 ... Truncated |
