Submission details
Task:Monikulmio
Sender:3lv11ra
Submission time:2025-11-09 21:07:53 +0200
Language:C++ (C++17)
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.01 s10details

Code

#include <bits/stdc++.h>
using namespace std;

struct Point {
    int y, x;
    bool operator==(const Point &other) const {
        return y == other.y && x == other.x;
    }
};

// Palauttaa luvun etumerkin (-1, 0, 1)
int sign(int a) {
    return (a > 0) - (a < 0);
}

// Tarkistaa, leikkaako p1->p2 segmentti vaakasuoran viivan y = row, vasemmalta oikealle
bool intersects(const Point &p1, const Point &p2, int row, double &xint) {
    int y1 = p1.y, x1 = p1.x;
    int y2 = p2.y, x2 = p2.x;
    if (y1 == y2) return false;
    if ((row < min(y1,y2)) || (row >= max(y1,y2))) return false;
    xint = x1 + (double)(x2 - x1) * (row - y1) / (y2 - y1);
    return true;
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<Point> pts(k);
    for (int i = 0; i < k; i++) {
        int y, x; cin >> y >> x;
        pts[i] = {y-1, x-1};
    }

    vector<string> grid(n, string(m,'.'));

    // Piirretään janat
    for (int i = 0; i < k; i++) {
        Point p1 = pts[i], p2 = pts[(i+1)%k];
        int dy = sign(p2.y - p1.y), dx = sign(p2.x - p1.x);
        int y = p1.y, x = p1.x;
        while (true) {
            if ((y==p1.y && x==p1.x) || (y==p2.y && x==p2.x) || find(pts.begin(), pts.end(), Point{y,x}) != pts.end())
                grid[y][x] = '*';
            else {
                char ch;
                if (dy==0) ch='=';
                else if (dx==0) ch='|';
                else if (dy==dx) ch='\\';
                else ch='/';
                grid[y][x] = ch;
            }
            if (y==p2.y && x==p2.x) break;
            y += dy; x += dx;
        }
    }

    // Täytetään sisäpuoli ray-castingilla
    for (int y = 0; y < n; y++) {
        vector<double> xints;
        for (int i = 0; i < k; i++) {
            double xint;
            if (intersects(pts[i], pts[(i+1)%k], y, xint))
                xints.push_back(xint);
        }
        sort(xints.begin(), xints.end());
        for (size_t j = 0; j+1 < xints.size(); j += 2) {
            int xstart = ceil(xints[j]);
            int xend = floor(xints[j+1]);
            for (int x = xstart; x <= xend; x++)
                if (grid[y][x]=='.') grid[y][x] = '#';
        }
    }

    for (auto &row: grid) cout << row << "\n";
}

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