| Task: | Monikulmio |
| Sender: | asonnine |
| Submission time: | 2025-10-27 11:09:11 +0200 |
| Language: | Rust (2021) |
| Status: | READY |
| Result: | 87 |
| group | verdict | score |
|---|---|---|
| #1 | RUNTIME ERROR | 87 |
| test | verdict | time | score | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 10 | details |
| #2 | ACCEPTED | 0.00 s | 10 | details |
| #3 | ACCEPTED | 0.00 s | 10 | details |
| #4 | ACCEPTED | 0.00 s | 10 | details |
| #5 | ACCEPTED | 0.00 s | 10 | details |
| #6 | ACCEPTED | 0.00 s | 10 | details |
| #7 | ACCEPTED | 0.00 s | 10 | details |
| #8 | ACCEPTED | 0.00 s | 10 | details |
| #9 | RUNTIME ERROR | 0.00 s | 0 | details |
| #10 | ACCEPTED | 0.00 s | 7 | details |
Code
use std::{
io,
ops::{Add, Sub},
usize, vec,
};
#[derive(Clone, Copy, Debug)]
struct Pair {
x: isize,
y: isize,
}
#[derive(Clone, Copy, Debug)]
enum Direction {
VERTICAL,
HORIZONTAL,
RIGHT,
LEFT,
NONE,
}
impl Sub for Pair {
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
Pair {
x: self.x - rhs.x,
y: self.y - rhs.y,
}
}
}
impl Add for Pair {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Pair {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
}
impl Pair {
fn direction(self) -> Direction {
use Direction::*;
match (self.x.cmp(&0), self.y.cmp(&0)) {
(std::cmp::Ordering::Less, std::cmp::Ordering::Less) => LEFT,
(std::cmp::Ordering::Less, std::cmp::Ordering::Equal) => HORIZONTAL,
(std::cmp::Ordering::Less, std::cmp::Ordering::Greater) => RIGHT,
(std::cmp::Ordering::Equal, std::cmp::Ordering::Less) => VERTICAL,
(std::cmp::Ordering::Equal, std::cmp::Ordering::Equal) => NONE,
(std::cmp::Ordering::Equal, std::cmp::Ordering::Greater) => VERTICAL,
(std::cmp::Ordering::Greater, std::cmp::Ordering::Less) => RIGHT,
(std::cmp::Ordering::Greater, std::cmp::Ordering::Equal) => HORIZONTAL,
(std::cmp::Ordering::Greater, std::cmp::Ordering::Greater) => LEFT,
}
}
fn len(self) -> isize {
isize::max(self.x.abs(), self.y.abs())
}
fn normalise(self) -> Pair {
match self.direction() {
Direction::VERTICAL => {
if self.y > 0 {
Pair { x: 0, y: 1 }
} else {
Pair { x: 0, y: -1 }
}
}
Direction::HORIZONTAL => {
if self.x > 0 {
Pair { x: 1, y: 0 }
} else {
Pair { x: -1, y: 0 }
}
}
Direction::RIGHT => {
if self.y > 0 {
Pair { x: -1, y: 1 }
} else {
Pair { x: 1, y: -1 }
}
}
Direction::LEFT => {
if self.x > 0 {
Pair { x: 1, y: 1 }
} else {
Pair { x: -1, y: -1 }
}
}
Direction::NONE => Pair { x: 0, y: 0 },
}
}
fn scale(self, scale: isize) -> Pair {
Pair {
x: self.x * scale,
y: self.y * scale,
}
}
}
impl Direction {
fn char(self) -> char {
match self {
Direction::VERTICAL => '|',
Direction::HORIZONTAL => '=',
Direction::RIGHT => '/',
Direction::LEFT => '\\',
Direction::NONE => 'E',
}
}
}
fn main() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let (n, m, k): (usize, usize, usize) = {
let mut iter = input.split_whitespace();
(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
)
};
let mut vertices: Vec<Pair> = Vec::with_capacity(k);
for _ in 0..k {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let (y, x): (isize, isize) = {
let mut iter = input.split_whitespace();
(
iter.next().unwrap().parse::<isize>().unwrap() - 1,
iter.next().unwrap().parse::<isize>().unwrap() - 1,
)
};
vertices.push(Pair { x, y });
}
let mut canvas = vec![vec!['.'; m]; n];
for i in 0..k as usize {
let start_point = vertices[i];
let end_point = vertices[(i + 1) % k];
let diff = end_point - start_point;
let dir = diff.direction();
canvas[start_point.y as usize][start_point.x as usize] = '*';
for i in 1..diff.len() {
let point = start_point + diff.normalise().scale(i);
canvas[point.y as usize][point.x as usize] = dir.char();
}
}
for i in 0..k as usize {
let start_point = vertices[i];
let diff = vertices[(i + 1) % k] - start_point;
let dir = diff.direction();
let midpoint = start_point + diff.normalise().scale(diff.len() / 2);
match dir {
Direction::VERTICAL => {
if !(canvas[midpoint.y as usize][midpoint.x as usize + 1] == '.'
&& canvas[midpoint.y as usize][midpoint.x as usize - 1] == '.')
{
continue;
}
let mut clone1 = canvas.clone();
if fill(&mut clone1, midpoint + Pair { x: 1, y: 0 }) == Ok(()) {
canvas = clone1;
break;
}
let mut clone2 = canvas.clone();
if fill(&mut clone2, midpoint + Pair { x: -1, y: 0 }) == Ok(()) {
canvas = clone2;
break;
}
continue;
}
Direction::HORIZONTAL => {
if !(canvas[midpoint.y as usize + 1][midpoint.x as usize] == '.'
&& canvas[midpoint.y as usize - 1][midpoint.x as usize] == '.')
{
continue;
}
let mut clone1 = canvas.clone();
if fill(&mut clone1, midpoint + Pair { x: 0, y: 1 }) == Ok(()) {
canvas = clone1;
break;
}
let mut clone2 = canvas.clone();
if fill(&mut clone2, midpoint + Pair { x: 0, y: -1 }) == Ok(()) {
canvas = clone2;
break;
}
continue;
}
Direction::RIGHT => {
if !(canvas[midpoint.y as usize][midpoint.x as usize + 1] == '.'
&& canvas[midpoint.y as usize][midpoint.x as usize - 1] == '.')
{
continue;
}
let mut clone1 = canvas.clone();
if fill(&mut clone1, midpoint + Pair { x: 1, y: 0 }) == Ok(()) {
canvas = clone1;
break;
}
let mut clone2 = canvas.clone();
if fill(&mut clone2, midpoint + Pair { x: -1, y: 0 }) == Ok(()) {
canvas = clone2;
break;
}
continue;
}
Direction::LEFT => {
if !(canvas[midpoint.y as usize + 1][midpoint.x as usize] == '.'
&& canvas[midpoint.y as usize - 1][midpoint.x as usize] == '.')
{
continue;
}
let mut clone1 = canvas.clone();
if fill(&mut clone1, midpoint + Pair { x: 0, y: 1 }) == Ok(()) {
canvas = clone1;
break;
}
let mut clone2 = canvas.clone();
if fill(&mut clone2, midpoint + Pair { x: 0, y: -1 }) == Ok(()) {
canvas = clone2;
break;
}
continue;
}
Direction::NONE => continue,
}
}
for line in canvas {
for character in line {
print!("{}", character);
}
println!();
}
}
fn fill(canvas: &mut Vec<Vec<char>>, point: Pair) -> Result<(), ()> {
if canvas[point.y as usize][point.x as usize] == '.' {
canvas[point.y as usize][point.x as usize] = '#';
} else {
return Ok(());
}
if point.x == 0
|| point.y == 0
|| point.x as usize == canvas[0].len() - 1
|| point.y as usize == canvas.len() - 1
{
return Err(());
}
let returns = [
fill(canvas, point + Pair { x: 1, y: 0 }),
fill(canvas, point + Pair { x: -1, y: 0 }),
fill(canvas, point + Pair { x: 0, y: 1 }),
fill(canvas, point + Pair { x: 0, y: -1 }),
];
if returns.iter().all(|x| *x == Ok(())) {
return Ok(());
} else {
return Err(());
}
}
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: RUNTIME ERROR
| input |
|---|
| 50 100 142 1 1 1 7 1 11 1 14 ... |
| correct output |
|---|
| *=====*===*==*................... |
| user output |
|---|
| (empty) |
Error:
thread 'main' panicked at input/code.rs:180:30: index out of bounds: the len is 50 but the index is 18446744073709551615 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
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 '.'
