Submission details
Task:Monikulmio
Sender:Jaksu
Submission time:2025-10-28 09:37:16 +0200
Language:Rust (2021)
Status:READY
Result:84
Feedback
groupverdictscore
#184
Test results
testverdicttimescore
#1ACCEPTED0.00 s10details
#2ACCEPTED0.00 s10details
#3ACCEPTED0.00 s10details
#4ACCEPTED0.00 s10details
#5ACCEPTED0.00 s10details
#6ACCEPTED0.00 s10details
#7ACCEPTED0.00 s10details
#80.00 s0details
#9ACCEPTED0.00 s7details
#10ACCEPTED0.00 s7details

Compiler report

warning: value assigned to `point` is never read
  --> input/code.rs:19:13
   |
19 |     let mut point = (0,0);
   |             ^^^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

warning: 1 warning emitted

Code

use std::{io, str::SplitAsciiWhitespace};
pub fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("Failed to read input");
    
    let mut substringiter = input.split_ascii_whitespace();
    
    let height = parse(&mut substringiter);
    let width = parse(&mut substringiter);
    let mut grid: Vec<Vec<u8>> = vec!();
    let rowtext = ".".repeat(width);
    for _rownum in 0..height {
        grid.push(rowtext.as_bytes().to_vec());
    }

    let pointamount = parse(&mut substringiter);
    let mut previouspoint = (0, 0);
    let mut firstpoint = (0, 0);
    let mut point = (0,0);

    for index in 0..(pointamount+1) {
        if index != pointamount {
            point = get_point();
        } else {
            point = firstpoint;
        }

        grid[point.0][point.1] = 42;

        if index != 0 {
            let dy = point.0 as isize - previouspoint.0 as isize;
            let dx = point.1 as isize - previouspoint.1 as isize;

            if dx == 0 {
                let rangey = range(previouspoint.0, point.0);
                for rownum in rangey {
                    grid[rownum][point.1] = 124;
                }
            } else {
                let kulmakerroin = dy/dx;
                let character: u8 = match kulmakerroin {
                    1 => 92,
                    0 => 61,
                    -1 => 47,
                    _ => 0,
                };

                let rangex = range(previouspoint.1, point.1);

                for column in rangex {
                    let y = (previouspoint.0 as isize +(column as isize -previouspoint.1 as isize)*kulmakerroin) as usize;
                    grid[y][column] = character;
                }
            }
        } else {
            firstpoint = point;
        }

        previouspoint = point;
    }

    let startpoint = find_inside(&grid);
    dbg!(startpoint);

    fill(&mut grid, startpoint);

    printresult(&grid);
}

pub fn parse(iter: &mut SplitAsciiWhitespace) -> usize {
    let s = match iter.next() {
        Some(s) => s.parse().unwrap(),
        None => 0,
    };
    return s;
}

pub fn range(previouspointcoord: usize, pointcoord: usize) -> std::ops::Range<usize> {
    let range: std::ops::Range<usize> = match pointcoord > previouspointcoord {
        true => (previouspointcoord+1)..pointcoord,
        false => (pointcoord+1)..previouspointcoord,
    };
    return range;
}

pub fn get_point() -> (usize, usize) {
    let mut point = String::new();
    io::stdin().read_line(&mut point).expect("Failed to read input");

    let mut pointiter = point.split_ascii_whitespace();
    let y = parse(&mut pointiter)-1;
    let x = parse(&mut pointiter)-1;
    let output = (y, x);
    return output;
}

pub fn find_inside(grid: &Vec<Vec<u8>>) -> (usize, usize) {
    let mut output: (usize, usize) = (0, 0);
    let mut edges = 0;
    for rownum in 0..grid.len() {
        for colnum in 0..grid[rownum].len() {
            let char = grid[rownum][colnum];
            if char == 42 {
                break;
            }
            if char != 61 && char != 46 {
                edges += 1;
                if edges%2 == 1 {
                    if grid[rownum][colnum+1] == 46 {
                        output = (rownum, colnum+1);
                        break;
                }
                }
            }
        }
        if output != (0, 0) {
            break;
        }
    }
    return output;
}

pub fn fill(grid: &mut Vec<Vec<u8>>, point: (usize, usize)) {
    if grid[point.0][point.1] != 35 {
        if grid[point.0][point.1] == 46 {
            grid[point.0][point.1] = 35;
            fill(grid, (point.0-1, point.1));
            fill(grid, (point.0+1, point.1));
            fill(grid, (point.0, point.1-1));
            fill(grid, (point.0, point.1+1));
        }
    }
} 

pub fn printresult(grid: &Vec<Vec<u8>>) {
    let mut stringgrid: Vec<&str> = vec!();
    for row in grid {
        let charrow = &row[..];
        let s = match std::str::from_utf8(charrow) {
            Ok(v) => v,
            Err(_e) => panic!(),
        };
        stringgrid.push(s);
    }

    for row in stringgrid {
        println!("{}", row);
    }
}

Test details

Test 1 (public)

Verdict: ACCEPTED

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

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

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

Error:
[input/code.rs:63] startpoint = (
    2,
    4,
)

Test 2 (public)

Verdict: ACCEPTED

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

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

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

Error:
[input/code.rs:63] startpoint = (
    5,
    10,
)

Test 3 (public)

Verdict: ACCEPTED

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

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

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

Error:
[input/code.rs:63] startpoint = (
    3,
    29,
)

Test 4 (public)

Verdict: ACCEPTED

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

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

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

Error:
[input/code.rs:63] startpoint = (
    3,
    9,
)

Test 5 (public)

Verdict: ACCEPTED

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

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

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

Error:
[input/code.rs:63] startpoint = (
    3,
    19,
)

Test 6 (public)

Verdict: ACCEPTED

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

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

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

Error:
[input/code.rs:63] startpoint = (
    3,
    2,
)

Test 7 (public)

Verdict: ACCEPTED

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

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

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

Error:
[input/code.rs:63] startpoint = (
    6,
    9,
)

Test 8 (public)

Verdict:

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

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

user output
(empty)

Error:
[input/code.rs:63] startpoint = (
    0,
    0,
)
thread 'main' panicked at input/code.rs:124:12:
index out of bounds: the len is 40 but the index is 18446744073709551615
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Test 9 (public)

Verdict: ACCEPTED

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

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

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

Feedback: Lines are drawn correctly. Incorrect fill character on row 2, col 11: expected '#', got '.'
Error:
[input/code.rs:63] startpoint = (
    3,
    8,
)

Test 10 (public)

Verdict: ACCEPTED

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

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

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

Feedback: Lines are drawn correctly. Incorrect fill character on row 2, col 86: expected '#', got '.'
Error:
[input/code.rs:63] startpoint = (
    1,
    5,
)