Task: | Ratsun reitit |
Sender: | jkan |
Submission time: | 2020-10-07 15:16:58 +0300 |
Language: | Rust |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 27 |
#2 | ACCEPTED | 31 |
#3 | ACCEPTED | 42 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#8 | ACCEPTED | 0.01 s | 2, 3 | details |
#9 | ACCEPTED | 0.01 s | 2, 3 | details |
#10 | ACCEPTED | 0.01 s | 2, 3 | details |
#11 | ACCEPTED | 0.02 s | 3 | details |
#12 | ACCEPTED | 0.04 s | 3 | details |
#13 | ACCEPTED | 0.04 s | 3 | details |
Compiler report
warning: function is never used: `recurse_knight_moves` --> input/code.rs:37:4 | 37 | fn recurse_knight_moves( | ^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
Code
use std::io::{BufRead, BufReader};use std::collections::VecDeque;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 iterate_knight_moves(board: &mut Vec<Vec<Option<i32>>>,pos0: Move) {let mut note: Vec<Move> = Vec::new();let mut queue: VecDeque<(Move, i32)> = VecDeque::from(vec![(pos0,0)]);let moves_vec = 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 mut moves;let mut pos: Move;let mut depth: i32;let bsize = board.len() as i32;while !queue.is_empty() {match queue.pop_front().unwrap() {(x,y) => {pos = x; depth = y;},};moves = moves_vec.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)})for t in moves {let v = board[t.0 as usize][t.1 as usize];if v.unwrap_or(i32::MAX) > depth {board[t.0 as usize][t.1 as usize] = Some(depth);if !note.contains(&t) {queue.push_back((t,depth+1))}}}note.push(pos);}}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);iterate_knight_moves(&mut board, Move(-2,-1));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: ACCEPTED
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 3 2 3 4 1 2 3 2 1 4 3 2 3 2 3 2 3 2 3 2 3 4 |
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
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 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 ... |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
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 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 ... Truncated |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
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 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 ... Truncated |
Test 6
Group: 1, 2, 3
Verdict: ACCEPTED
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 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 ... Truncated |
Test 7
Group: 1, 2, 3
Verdict: ACCEPTED
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 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 ... Truncated |
Test 8
Group: 2, 3
Verdict: ACCEPTED
input |
---|
25 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... Truncated |
Test 9
Group: 2, 3
Verdict: ACCEPTED
input |
---|
49 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... Truncated |
Test 10
Group: 2, 3
Verdict: ACCEPTED
input |
---|
50 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... Truncated |
Test 11
Group: 3
Verdict: ACCEPTED
input |
---|
75 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... Truncated |
Test 12
Group: 3
Verdict: ACCEPTED
input |
---|
99 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... Truncated |
Test 13
Group: 3
Verdict: ACCEPTED
input |
---|
100 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... Truncated |