Submission details
Task:Monikulmio
Sender:3lv11ra
Submission time:2025-11-09 21:06:55 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

In file included from /usr/include/c++/11/bits/stl_algobase.h:71,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_equals_val<_Value>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >; _Value = const Point]':
/usr/include/c++/11/bits/stl_algobase.h:2069:14:   required from '_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const Point>]'
/usr/include/c++/11/bits/stl_algobase.h:2114:23:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predic...

Code

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

struct Point {
    int y, 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; // vaakasuora segmentti ei lasketa
    if ((row < min(y1,y2)) || (row >= max(y1,y2))) return false;
    // lineaarinen interpolaatio
    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";
}