Submission details
Task:Monikulmio
Sender:Lily2
Submission time:2025-11-09 21:16:48 +0200
Language:C
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.00 s10details
#9ACCEPTED0.00 s10details
#10ACCEPTED0.02 s10details

Compiler report

input/code.c: In function 'main':
input/code.c:30:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d %d", &y, &x);
      |     ^~~~~~~~~~~~~~~~~~~~~~

Code

#include <stdio.h>
#include <stdlib.h>

typedef struct { int y, x; } Pt;

static int sgn(int v) { return (v > 0) - (v < 0); }
static int imax(int a, int b) { return a > b ? a : b; }

// Even-odd point-in-polygon test
static int pip(double px, double py, const double *vx, const double *vy, int k) {
  int inside = 0;
  for (int i = 0, j = k - 1; i < k; j = i++) {
    int yiAbove = vy[i] > py;
    int yjAbove = vy[j] > py;
    if (yiAbove != yjAbove) {
      double xInt = vx[i] + (vx[j] - vx[i]) * (py - vy[i]) / (vy[j] - vy[i]);
      if (px < xInt) inside ^= 1;
    }
  }
  return inside;
}

int main(void) {
  int n, m, k;
  if (scanf("%d %d %d", &n, &m, &k) != 3) return 0;

  Pt *p = (Pt *)malloc(sizeof(Pt) * k);
  for (int i = 0; i < k; i++) {
    int y, x;
    scanf("%d %d", &y, &x);
    p[i].y = y - 1;
    p[i].x = x - 1;
  }

  char **g = (char **)malloc(n * sizeof(*g));
  for (int i = 0; i < n; i++) {
    g[i] = (char *)malloc(m * sizeof(**g));
    for (int j = 0; j < m; j++) g[i][j] = '.';
  }

  // Draw edges
  for (int i = 0; i < k; i++) {
    Pt a = p[i];
    Pt b = p[(i + 1) % k];

    int dy = sgn(b.y - a.y);
    int dx = sgn(b.x - a.x);
    int steps = imax(abs(b.y - a.y), abs(b.x - a.x));

    char ec;
    if (dy == 0) ec = '=';
    else if (dx == 0) ec = '|';
    else if (dx * dy < 0) ec = '/';
    else ec = '\\';

    for (int j = 0; j < steps; j++) {
      int y = a.y + j * dy;
      int x = a.x + j * dx;
      if (y >= 0 && y < n && x >= 0 && x < m) g[y][x] = ec;
    }
  }

  // Draw corners
  for (int i = 0; i < k; i++) {
    int y = p[i].y, x = p[i].x;
    if (y >= 0 && y < n && x >= 0 && x < m) g[y][x] = '*';
  }

  // Build polygon at cell centers
  double *vx = (double *)malloc(k * sizeof(double));
  double *vy = (double *)malloc(k * sizeof(double));
  for (int i = 0; i < k; i++) {
    vx[i] = (double)p[i].x + 0.5;
    vy[i] = (double)p[i].y + 0.5;
  }

  // Fill interior cells
  for (int y = 0; y < n; y++) {
    double cy = (double)y + 0.5;
    for (int x = 0; x < m; x++) {
      if (g[y][x] != '.') continue;  // Skip edges and corners
      double cx = (double)x + 0.5;
      if (pip(cx, cy, vx, vy, k)) g[y][x] = '#';
    }
  }

  // Output
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) putchar(g[i][j]);
    putchar('\n');
  }

  // Cleanup
  for (int i = 0; i < n; i++) free(g[i]);
  free(g);
  free(p);
  free(vx);
  free(vy);
  return 0;
}

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