Submission details
Task:Monikulmio
Sender:madde
Submission time:2025-10-28 18:40:44 +0200
Language:Rust (2021)
Status:READY
Result:7
Feedback
groupverdictscore
#17
Test results
testverdicttimescore
#1ACCEPTED0.00 s7details
#20.00 s0details
#30.00 s0details
#40.00 s0details
#50.00 s0details
#60.00 s0details
#70.00 s0details
#80.00 s0details
#90.00 s0details
#100.00 s0details

Compiler report

warning: unused import: `stdin`
 --> input/code.rs:1:30
  |
1 | use std::io::{self, BufRead, stdin};
  |                              ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `BufRead`
 --> input/code.rs:1:21
  |
1 | use std::io::{self, BufRead, stdin};
  |                     ^^^^^^^

warning: unused `Result` that must be used
 --> input/code.rs:9:5
  |
9 |     input.read_line(&mut input_buf);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this `Result` may be an `Err` variant, which should be handled
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
9 |     let _ = input.read_line(&mut input_buf);
  |     +++++++

warning: unused `Result` that must be used
  --> input/code.rs:18:9
   |
18 |         input.read_line(&mut input_buf);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled
help: use `let _ = ...`...

Code

use std::io::{self, BufRead, stdin};
// use std::time::Instant;

const X: usize = 0;
const Y: usize = 1;
fn main() {
    let input = io::stdin();
    let mut input_buf: String = "".to_string();
    input.read_line(&mut input_buf);
    let line1: Vec<&str> = input_buf.split_whitespace().collect();
    // let start_time = Instant::now();
    let height: u32 = line1[X].parse().unwrap();
    let width: u32 = line1[Y].parse().unwrap();
    let vertex_count: u32 = line1[2].parse().unwrap();
    let mut vertecies: Vec<[u32; 2]> = vec![];
    for _i in 0..vertex_count {
        input_buf = "".to_string();
        input.read_line(&mut input_buf);
        input_buf = input_buf.trim().to_string();
        let input_nums: Vec<&str> = input_buf.split_whitespace().collect();
        let point_coord = [
            input_nums[Y].parse::<u32>().unwrap(),
            input_nums[X].parse::<u32>().unwrap(),
        ];
        vertecies.push(point_coord);
    }
    let mut grid = draw_lines(width, height, &vertecies);
    draw_dots(&mut grid, &vertecies);
    print_grid(&grid);
    // println!("{}", start_time.elapsed().as_millis())
}

fn draw_dots(grid: &mut Vec<Vec<char>>, vertecies: &Vec<[u32; 2]>) {
    for vertex in vertecies {
        draw(grid, vertex, '*');
    }
}

fn print_grid(grid: &Vec<Vec<char>>) {
    for line in grid.iter() {
        for symbol in line.iter() {
            print!("{symbol}");
        }
        println!("")
    }
}

fn draw(grid: &mut Vec<Vec<char>>, position: &[u32; 2], thing: char) {
    grid[position[Y] as usize - 1][position[X] as usize - 1] = thing;
}
fn in_bounds(pos: [u32; 2], width: u32, height: u32) -> bool {
    if pos[X] < width && pos[Y] < height {
        return true;
    } else {
        return false;
    }
}

fn draw_lines(width: u32, height: u32, vertecies: &Vec<[u32; 2]>) -> Vec<Vec<char>> {
    let mut grid: Vec<Vec<char>> = vec![vec!['.'; width as usize]; height as usize];
    let mut cursor: [u32; 2] = [0, 0];

    for i in 0..vertecies.len() {
        cursor[X] = vertecies[i][X];
        cursor[Y] = vertecies[i][Y];
        if vertecies[i][X] == vertecies[(i + 1) % vertecies.len()][X] {
            //yhtä kuin
            if vertecies[i][Y] < vertecies[(i + 1) % vertecies.len()][Y] {
                while cursor[Y] != vertecies[(i + 1) % vertecies.len()][Y]
                    && in_bounds(cursor, width, height)
                {
                    draw(&mut grid, &cursor, '|');
                    cursor[Y] += 1;
                }
            } else {
                while cursor[Y] != vertecies[(i + 1) % vertecies.len()][Y]
                    && in_bounds(cursor, width, height)
                {
                    draw(&mut grid, &cursor, '|');
                    cursor[Y] -= 1;
                }
            }
        } else if vertecies[i][X] > vertecies[(i + 1) % vertecies.len()][X] {
            //suurempi
            if vertecies[i][Y] < vertecies[(i + 1) % vertecies.len()][Y] {
                while cursor[Y] != vertecies[(i + 1) % vertecies.len()][Y]
                    && in_bounds(cursor, width, height)
                {
                    draw(&mut grid, &cursor, '/');
                    cursor[Y] += 1;
                    cursor[X] += 1;
                }
            } else if vertecies[i][Y] > vertecies[(i + 1) % vertecies.len()][Y] {
                while cursor[Y] != vertecies[(i + 1) % vertecies.len()][Y]
                    && in_bounds(cursor, width, height)
                {
                    draw(&mut grid, &cursor, '\\');
                    cursor[Y] -= 1;
                    cursor[X] -= 1;
                }
            } else {
                while cursor[X] != vertecies[(i + 1) % vertecies.len()][X]
                    && in_bounds(cursor, width, height)
                {
                    draw(&mut grid, &cursor, '=');
                    cursor[X] -= 1;
                }
            }
        } else {
            //vähempi
            if vertecies[i][Y] < vertecies[(i + 1) % vertecies.len()][Y] {
                while cursor[Y] != vertecies[(i + 1) % vertecies.len()][Y]
                    && in_bounds(cursor, width, height)
                {
                    draw(&mut grid, &cursor, '\\');
                    cursor[Y] += 1;
                    cursor[X] += 1;
                }
            } else if vertecies[i][Y] > vertecies[(i + 1) % vertecies.len()][Y] {
                while cursor[Y] != vertecies[(i + 1) % vertecies.len()][Y]
                    && in_bounds(cursor, width, height)
                {
                    draw(&mut grid, &cursor, '/');
                    cursor[Y] -= 1;
                    cursor[X] += 1;
                }
            } else {
                while cursor[X] != vertecies[(i + 1) % vertecies.len()][Y]
                    && in_bounds(cursor, width, height)
                {
                    draw(&mut grid, &cursor, '=');
                    cursor[X] += 1;
                }
            }
        }
    }
    return grid;
}

Test details

Test 1 (public)

Verdict: ACCEPTED

input
8 9 5
5 2
2 5
5 8
7 8
...

correct output
.........
....*....
.../#\...
../###\..
.*#####*.
...

user output
.........
....*....
.../.\...
../...\..
.*.....*.
...

Feedback: Lines are drawn correctly. Incorrect fill character on row 3, col 5: expected '#', got '.'

Test 2 (public)

Verdict:

input
20 40 4
5 10
5 30
15 30
15 10

correct output
.................................

user output
.................................

Feedback: Incorrect character on row 5, col 31: expected '.', got '='

Test 3 (public)

Verdict:

input
20 40 29
8 7
13 2
14 2
9 7
...

correct output
.................................

user output
.................................

Feedback: Incorrect character on row 4, col 29: expected '/', got '.'

Test 4 (public)

Verdict:

input
20 40 14
5 12
5 25
8 28
13 28
...

correct output
.................................

user output
.................................

Feedback: Incorrect character on row 5, col 26: expected '#', got '='

Test 5 (public)

Verdict:

input
20 40 12
3 20
7 16
7 9
11 13
...

correct output
.................................

user output
.................................

Feedback: Incorrect character on row 4, col 19: expected '/', got '.'

Test 6 (public)

Verdict:

input
9 35 33
2 3
2 8
4 8
4 5
...

correct output
.................................

user output
.................................

Feedback: Incorrect character on row 2, col 9: expected '.', got '='

Test 7 (public)

Verdict:

input
30 100 69
6 10
6 14
7 14
7 18
...

correct output
.................................

user output
.................................

Feedback: Incorrect character on row 6, col 15: expected '.', got '='

Test 8 (public)

Verdict:

input
40 60 192
11 3
11 5
10 6
11 7
...

correct output
.................................

user output
.................................

Feedback: Incorrect character on row 3, col 30: expected '#', got '='

Test 9 (public)

Verdict:

input
50 100 142
1 1
1 7
1 11
1 14
...

correct output
*=====*===*==*...................

user output
*.....*===*==*================...

Feedback: Incorrect character on row 1, col 2: expected '=', got '.'

Test 10 (public)

Verdict:

input
100 100 1000
10 1
4 7
1 4
1 9
...

correct output
...*====*........................

user output
...*====*=====================...

Feedback: Incorrect character on row 1, col 10: expected '.', got '='