| Task: | Monikulmio |
| Sender: | NicholasAhman |
| Submission time: | 2025-11-19 13:46:57 +0200 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 100 |
| test | verdict | time | score | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | 10 | details |
| #2 | ACCEPTED | 0.05 s | 10 | details |
| #3 | ACCEPTED | 0.06 s | 10 | details |
| #4 | ACCEPTED | 0.06 s | 10 | details |
| #5 | ACCEPTED | 0.06 s | 10 | details |
| #6 | ACCEPTED | 0.05 s | 10 | details |
| #7 | ACCEPTED | 0.08 s | 10 | details |
| #8 | ACCEPTED | 0.08 s | 10 | details |
| #9 | ACCEPTED | 0.08 s | 10 | details |
| #10 | ACCEPTED | 0.26 s | 10 | details |
Code
import sys
def solve():
# Read all input from stdin
input_data = sys.stdin.read().split()
if not input_data:
return
iterator = iter(input_data)
try:
n = int(next(iterator))
m = int(next(iterator))
k = int(next(iterator))
points = []
for _ in range(k):
# Read y (row) and x (col).
# Convert 1-based input to 0-based implementation coordinates.
y = int(next(iterator)) - 1
x = int(next(iterator)) - 1
points.append((y, x))
except StopIteration:
return
# Initialize grid with '.' (outside)
grid = [['.' for _ in range(m)] for _ in range(n)]
# --- PHASE 1: DRAW BOUNDARIES ---
# Helper to get direction sign
def get_sign(val):
if val > 0: return 1
if val < 0: return -1
return 0
# Draw edges
for i in range(k):
p1 = points[i]
p2 = points[(i + 1) % k] # Wrap around to start
r1, c1 = p1
r2, c2 = p2
# Determine steps and direction
dr = get_sign(r2 - r1)
dc = get_sign(c2 - c1)
# Determine character based on slope
char = ''
if r1 == r2:
char = '='
elif c1 == c2:
char = '|'
else:
# Diagonals:
# If dr and dc have same sign (both pos or both neg) -> \
# If different signs -> /
# Note: Row index increases downwards.
# (dr=1, dc=1) is down-right (\)
# (dr=-1, dc=1) is up-right (/)
if dr == dc:
char = '\\'
else:
char = '/'
# Draw the line segment
# We draw from p1 up to (but not including) p2 to avoid overwriting
# the next edge's start char logic, though standardizing vertices later fixes this.
curr_r, curr_c = r1, c1
steps = max(abs(r2 - r1), abs(c2 - c1))
for _ in range(steps):
grid[curr_r][curr_c] = char
curr_r += dr
curr_c += dc
# Draw corners (Always '*')
# Done after edges to ensure corners take precedence
for r, c in points:
grid[r][c] = '*'
# --- PHASE 2: FILL INTERIOR ---
boundary_chars = {'*', '-', '=', '|', '/', '\\'}
for r in range(n):
for c in range(m):
# If currently on a boundary, skip logic
if grid[r][c] in boundary_chars:
continue
intersections = 0
# Check ray intersection against all polygon edges
for i in range(k):
p1 = points[i]
p2 = points[(i + 1) % k]
y1, x1 = p1
y2, x2 = p2
# Ray Casting logic:
# Check if the edge spans across the current row 'r' vertically.
# We use strict inequality on one side to handle vertices (half-open interval).
# (y1 > r) != (y2 > r) is true if r is strictly between y1 and y2
# or equal to the lower one (depending on convention), effectively
# preventing double counting at vertices.
if (y1 > r) != (y2 > r):
# Calculate the x-coordinate where the edge intersects row r
# Formula derived from line equation:
# slope = (x2 - x1) / (y2 - y1)
# x_inters = x1 + (r - y1) * slope
x_inters = x1 + (r - y1) * (x2 - x1) / (y2 - y1)
# We only care if the intersection is to the RIGHT of our point
if c < x_inters:
intersections += 1
# If odd intersections, point is inside
if intersections % 2 == 1:
grid[r][c] = '#'
# --- OUTPUT ---
for row in grid:
print("".join(row))
if __name__ == "__main__":
solve()
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 |
|---|
| ...*====*........................ |
