Submission details
Task:Monikulmio
Sender:JuusoH
Submission time:2025-10-27 13:43:56 +0200
Language:Rust (2021)
Status:READY
Result:76
Feedback
groupverdictscore
#1ACCEPTED76
Test results
testverdicttimescore
#1ACCEPTED0.00 s10details
#2ACCEPTED0.00 s7details
#3ACCEPTED0.00 s7details
#4ACCEPTED0.00 s7details
#5ACCEPTED0.00 s7details
#6ACCEPTED0.00 s10details
#7ACCEPTED0.00 s7details
#8ACCEPTED0.00 s7details
#9ACCEPTED0.01 s7details
#10ACCEPTED0.01 s7details

Compiler report

warning: unused variable: `i`
  --> input/code.rs:12:9
   |
12 |     for i in 0..k {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `x`
  --> input/code.rs:24:13
   |
24 |         for x in 0..m {
   |             ^ help: if this is intentional, prefix it with an underscore: `_x`

warning: variable does not need to be mutable
   --> input/code.rs:127:9
    |
127 |     let mut x = pos.1;
    |         ----^
    |         |
    |         help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: variable does not need to be mutable
   --> input/code.rs:152:9
    |
152 |     let mut y = pos.0;
    |         ----^
    |         |
    |         help: remove this `mut`

warning: 4 warnings emitted

Code

use std::io;
fn main() {
    //input and setup
    let stdin = io::stdin();
    let mut input = String::new();
    _ = stdin.read_line(&mut input);
    let mut first_line = input.split_whitespace();
    let n: usize = first_line.next().unwrap().parse().unwrap();
    let m: usize = first_line.next().unwrap().parse().unwrap();
    let k: usize = first_line.next().unwrap().parse().unwrap();
    let mut points: Vec<(usize, usize)> = vec![];
    for i in 0..k {
        input.clear();
        _ = stdin.read_line(&mut input);
        let mut line = input.split_whitespace();
        let y: usize = line.next().unwrap().parse().unwrap();
        let x: usize = line.next().unwrap().parse().unwrap();
        points.push((y - 1, x - 1));
    }
    //init board
    let mut res: Vec<Vec<char>> = vec![];
    for y in 0..n {
        res.push(vec![]);
        for x in 0..m {
            res[y].push('.');
        }
    }
    //draw points
    for i in &points {
        res[i.0][i.1] = '*';
    }

    //draw lines
    for i in 0..k {
        let a = points[i];
        let b = points[(i + 1) % k];

        let mut y = a.0 as i32;
        let mut x = a.1 as i32;
        let mut deltax = 0;
        let mut deltay = 0;
        if a.0 < b.0 {
            deltay = 1;
        }
        if a.0 > b.0 {
            deltay = -1;
        }
        if a.1 < b.1 {
            deltax = 1;
        }
        if a.1 > b.1 {
            deltax = -1;
        }
        let mut symbol = '=';
        if deltay > 0 {
            if deltax > 0 {
                symbol = '\\';
            } else if deltax < 0 {
                symbol = '/';
            } else {
                symbol = '|';
            }
        } else if deltay < 0 {
            if deltax > 0 {
                symbol = '/';
            } else if deltax < 0 {
                symbol = '\\';
            } else {
                symbol = '|';
            }
        }
        loop {
            y += deltay;
            x += deltax;
            if y == b.0 as i32 && x == b.1 as i32 {
                break;
            }
            res[y as usize][x as usize] = symbol;
        }
    }

    //fill inside (partly)

    let res_copy = res.clone();

    for y in 0..n {
        for x in 0..m {
            if is_inside_polygon(&(y, x), &res_copy) && is_inside_polygon_side(&(y, x), &res_copy) {
                res[y][x] = '#';
            }
        }
    }

    //floodfill the rest (very cursed)
    for _ in 0..5 {
        for y in 0..n {
            for x in 0..m {
                if res[y][x] == '#' {
                    if y < n - 1 && res[y + 1][x] == '.' {
                        res[y + 1][x] = '#'
                    }
                    if y > 0 && res[y - 1][x] == '.' {
                        res[y - 1][x] = '#'
                    }
                    if x < m - 1 && res[y][x + 1] == '.' {
                        res[y][x + 1] = '#'
                    }
                    if x > 0 && res[y][x - 1] == '.' {
                        res[y][x - 1] = '#'
                    }
                }
            }
        }
    }

    //print board
    for y in 0..n {
        for x in 0..m {
            print!("{}", res[y][x]);
        }
        println!();
    }
}

fn is_inside_polygon(pos: &(usize, usize), res: &Vec<Vec<char>>) -> bool {
    let mut y = pos.0;
    let mut x = pos.1;

    if res[y][x] != '.' {
        return false;
    }
    if y == 0 {
        return false;
    }
    y -= 1;
    let mut intersects = 0;
    loop {
        if res[y][x] != '.' && res[y][x] != '|' {
            if res[y][x] != '|' {
                intersects += 1;
            }
        }
        if y == 0 {
            break;
        }
        y -= 1;
    }
    return intersects % 2 == 1;
}

fn is_inside_polygon_side(pos: &(usize, usize), res: &Vec<Vec<char>>) -> bool {
    let mut y = pos.0;
    let mut x = pos.1;

    if res[y][x] != '.' {
        return false;
    }
    if x == 0 {
        return false;
    }
    x -= 1;
    let mut intersects = 0;
    loop {
        if res[y][x] != '.' && res[y][x] != '|' {
            if res[y][x] != '|' {
                intersects += 1;
            }
        }
        if x == 0 {
            break;
        }
        x -= 1;
    }
    return intersects % 2 == 1;
}

Test details

Test 1 (public)

Verdict: ACCEPTED

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

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

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

Test 2 (public)

Verdict: ACCEPTED

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

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

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

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

Test 3 (public)

Verdict: ACCEPTED

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

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

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

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

Test 4 (public)

Verdict: ACCEPTED

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

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

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

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

Test 5 (public)

Verdict: ACCEPTED

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

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

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

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

Test 6 (public)

Verdict: ACCEPTED

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

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

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

Test 7 (public)

Verdict: ACCEPTED

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

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

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

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

Test 8 (public)

Verdict: ACCEPTED

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

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

user output
........................######...

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

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 17, col 18: expected '.', got '#'

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 1, col 10: expected '.', got '#'