| Task: | Monikulmio |
| Sender: | MatoCSES |
| Submission time: | 2025-10-27 20:46:44 +0200 |
| Language: | Rust (2021) |
| Status: | READY |
| Result: | 76 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 76 |
| test | verdict | time | score | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 10 | details |
| #2 | ACCEPTED | 0.00 s | 10 | details |
| #3 | ACCEPTED | 0.00 s | 7 | details |
| #4 | ACCEPTED | 0.00 s | 7 | details |
| #5 | ACCEPTED | 0.00 s | 7 | details |
| #6 | ACCEPTED | 0.00 s | 7 | details |
| #7 | ACCEPTED | 0.00 s | 7 | details |
| #8 | ACCEPTED | 0.00 s | 7 | details |
| #9 | ACCEPTED | 0.00 s | 7 | details |
| #10 | ACCEPTED | 0.01 s | 7 | details |
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(dx.abs(), dy.abs())-1) {
let y: i32 = p1.0 + dy.clamp(-1, 1) * (j + 1);
let x: i32 = p1.1 + dx.clamp(-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);
}
}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 |
|---|
| ................................. |
Feedback: Lines are drawn correctly. Incorrect fill character on row 3, col 31: 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 5, 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 7, col 17: expected '#', got '.'
Test 6 (public)
Verdict: ACCEPTED
| input |
|---|
| 9 35 33 2 3 2 8 4 8 4 5 ... |
| correct output |
|---|
| ................................. |
| user output |
|---|
| ................................. |
Feedback: Lines are drawn correctly. Incorrect fill character on row 3, col 3: expected '#', got '.'
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 10: 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 3, col 30: 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 2, col 11: 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 2, col 6: expected '#', got '.'
