Submission details
Task:Monikulmio
Sender:MatoCSES
Submission time:2025-10-27 20:43:23 +0200
Language:Rust (2021)
Status:COMPILE ERROR

Compiler report

error[E0433]: failed to resolve: use of undeclared crate or module `num`
  --> input/code.rs:55:31
   |
55 |         for j in 0..(cmp::max(num::abs(dx), num::abs(dy))-1) {
   |                               ^^^ use of undeclared crate or module `num`

error[E0433]: failed to resolve: use of undeclared crate or module `num`
  --> input/code.rs:55:45
   |
55 |         for j in 0..(cmp::max(num::abs(dx), num::abs(dy))-1) {
   |                                             ^^^ use of undeclared crate or module `num`

error[E0433]: failed to resolve: use of undeclared crate or module `num`
  --> input/code.rs:56:33
   |
56 |             let y: i32 = p1.0 + num::clamp(dy, -1, 1) * (j + 1);
   |                                 ^^^ use of undeclared crate or module `num`

error[E0433]: failed to resolve: use of undeclared crate or module `num`
  --> input/code.rs:57:33
   |
57 |             let x: i32 = p1.1 + num::clamp(dx, -1, 1) * (j + 1);
   |                                 ^^^ use of unde...

Code

use std::io;
use std::cmp;
use std::iter;

fn main() {
    let mut input: String = String::new();
    io::stdin().read_line(&mut input).unwrap();
    
    let input: Vec<i32> = input.trim().split(" ").map(|s| s.parse::<i32>().unwrap()).collect();

    let points: Vec<(i32, i32)> = get_points(input[2]);

    let mut polygon: Vec<String> = draw_grid(input[0], input[1], &points);
    polygon = draw_outlines(polygon, &points);
    polygon = fill_polygon(polygon);
    
    print_result(polygon);
}

fn get_points(k: i32) -> Vec<(i32, i32)> {
    let mut points: Vec<(i32, i32)> = Vec::new();
    for _ in 0..k {
        let mut point: String = String::new();
        io::stdin().read_line(&mut point).unwrap();
        let parsed: Vec<i32> = point.trim().split(" ").map(|s| s.parse::<i32>().unwrap()).collect();
        points.push((parsed[0]-1, parsed[1]-1));
    }
    return points;
}

fn draw_grid(n: i32, m: i32, points: &Vec<(i32, i32)>) -> Vec<String> {
    let mut polygon: Vec<String> = Vec::new();

    for y in 0..n {
        let mut row: String = String::new();
        for x in 0..m {
            let char: char = if !points.contains(&(y, x)) { '.' } else { '*' };
            row.push(char);
        };
        polygon.push(row);
    }

    return polygon;
}

fn draw_outlines(mut polygon: Vec<String>, points: &Vec<(i32, i32)>) -> Vec<String> {
    for i in 0..points.len() {
        let p1: (i32, i32) = points[i];
        let p2: (i32, i32) = points[(i+1)%points.len()];

        let dy: i32 = p2.0 - p1.0;
        let dx: i32 = p2.1 - p1.1;
        let c: char = if dx == 0 { 124 as char } else if dy == 0 { 61 as char } else if (dx < 0 && dy < 0) || (dx > 0 && dy > 0) { 92 as char } else { 47 as char };
        
        for j in 0..(cmp::max(num::abs(dx), num::abs(dy))-1) {
            let y: i32 = p1.0 + num::clamp(dy, -1, 1) * (j + 1);
            let x: i32 = p1.1 + num::clamp(dx, -1, 1) * (j + 1);
            polygon[y as usize].replace_range(x as usize..(x + 1) as usize, c.to_string().as_str());
        }
    }

    return polygon;
}

fn fill_polygon(mut polygon: Vec<String>) -> Vec<String> {
    for i in 0..polygon.len() {
        let indicies: Vec<usize> = polygon[i].match_indices(&['|', '=', '/', 92 as char, '*'][..]).map(|m| m.0).collect();
        if indicies.len() == 2 { polygon[i].replace_range(indicies[0]+1..indicies[1], iter::repeat("#").take(indicies[1]-indicies[0]-1).collect::<String>().as_str()); };
    }
    
    return polygon;
}

fn print_result(polygon: Vec<String>) {
    for row in polygon {
        println!("{}", row);
    }
}