Submission details
Task:Monikulmio
Sender:JuusoH
Submission time:2025-10-27 13:16:46 +0200
Language:Rust (2021)
Status:COMPILE ERROR

Compiler report

error[E0425]: cannot find function `is_inside_polygon_side` in this scope
   --> input/code.rs:88:57
    |
88  |             if is_inside_polygon(&(y, x), &res_copy) && is_inside_polygon_side(&(y, x), &res_copy) {
    |                                                         ^^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `is_inside_polygon`
...
103 | fn is_inside_polygon(pos: &(usize, usize), res: &Vec<Vec<char>>) -> bool {
    | ------------------------------------------------------------------------ similarly named function `is_inside_polygon` defined here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.

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

    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] = '#';
            }
        }
    }

    //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 asterisks = 0;
    let mut only_asterisks = true;
    let mut intersects = 0;
    loop {
        if y < 0 {
            break;
        }
        if res[y][x] != '.' && res[y][x] != '|' {
            intersects += 1;
        } else if res[y][x] == '*' {
            asterisks += 1;
        } else {
            only_asterisks = false;
        }
        if y == 0 {
            break;
        }
        y -= 1;
    }
    if only_asterisks {
        if asterisks > 0 {
            return false;
        }
    }
    return intersects % 2 == 1;
}