Submission details
Task:Monikulmio
Sender:JuusoH
Submission time:2025-11-08 19:30:06 +0200
Language:Rust (2021)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttimescore
#1ACCEPTED0.00 s10details
#2ACCEPTED0.00 s10details
#3ACCEPTED0.00 s10details
#4ACCEPTED0.00 s10details
#5ACCEPTED0.00 s10details
#6ACCEPTED0.00 s10details
#7ACCEPTED0.00 s10details
#8ACCEPTED0.01 s10details
#9ACCEPTED0.01 s10details
#10ACCEPTED0.04 s10details

Compiler report

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

warning: function `get_line_point_row_at_col` is never used
   --> input/code.rs:126:4
    |
126 | fn get_line_point_row_at_col(a: Pos, b: Pos, col: usize) -> usize {
    |    ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: variants `Center`, `Left`, and `Right` are never constructed
   --> input/code.rs:138:5
    |
137 | enum PointIntersection {
    |      ----------------- variants in this enum
138 |     Center,
    |     ^^^^^^
139 |     Left,
    |     ^^^^
140 |     Right,
    |     ^^^^^
    |
    = note: `PointIntersection` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis

warning: function `usize_to_char` is never used
   --> input/code.rs:143:4
    |
143 |...

Code

use std::io;

type Pos = (usize, usize);
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<Pos> = vec![];
    for _ 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('.');
        }
    }
    //fill inside

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

    //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;
        }
    }

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

fn is_inside_polygon_real(pos: Pos, points: &Vec<Pos>) -> bool {
    let n = points.len();

    let (px, py) = (pos.0 as f64, pos.1 as f64);
    let mut crossings = 0;

    for i in 0..n {
        let (x1, y1) = (points[i].0 as f64, points[i].1 as f64);
        let (x2, y2) = (points[(i + 1) % n].0 as f64, points[(i + 1) % n].1 as f64);

        if (y1 > py) != (y2 > py) {
            let x_intersect = x1 + (py - y1) * (x2 - x1) / (y2 - y1);

            //intersect only right
            if x_intersect >= px {
                crossings += 1;
            }
        }
    }

    crossings % 2 == 1
}

fn get_line_point_row_at_col(a: Pos, b: Pos, col: usize) -> usize {
    let mut deltay = 0;
    if a.0 < b.0 {
        deltay = 1;
    }
    if a.0 > b.0 {
        deltay = -1;
    }
    (a.0 as i32 + deltay * a.1.abs_diff(col) as i32) as usize
}
#[derive(Clone, Copy, PartialEq, Eq)]
enum PointIntersection {
    Center,
    Left,
    Right,
}

fn usize_to_char(u: usize) -> char {
    match u {
        0 => '0',
        1 => '1',
        2 => '2',
        3 => '3',
        4 => '4',
        5 => '5',
        6 => '6',
        7 => '7',
        _ => 'ö',
    }
}

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
.................................

Test 3 (public)

Verdict: ACCEPTED

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

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

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

Test 4 (public)

Verdict: ACCEPTED

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

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

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

Test 5 (public)

Verdict: ACCEPTED

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

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

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

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
.................................

Test 8 (public)

Verdict: ACCEPTED

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

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

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

Test 9 (public)

Verdict: ACCEPTED

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

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

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

Test 10 (public)

Verdict: ACCEPTED

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

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

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