Submission details
Task:Monikulmio
Sender:Jonde
Submission time:2025-10-27 19:03:05 +0200
Language:C++ (C++11)
Status:READY
Result:76
Feedback
groupverdictscore
#1ACCEPTED76
Test results
testverdicttimescore
#1ACCEPTED0.00 s10details
#2ACCEPTED0.00 s10details
#3ACCEPTED0.00 s7details
#4ACCEPTED0.00 s7details
#5ACCEPTED0.00 s7details
#6ACCEPTED0.00 s7details
#7ACCEPTED0.00 s7details
#8ACCEPTED0.00 s7details
#9ACCEPTED0.00 s7details
#10ACCEPTED0.01 s7details

Compiler report

input/code.cpp:88:5: warning: "/*" within comment [-Wcomment]
   88 |     /*if ( shape[coord_to_index(x-1, y) == '=']) { // shape[coord_to_index(x+1, y)]
      |

Code

#include <iostream>
#include <vector>
#include <tuple>
using namespace std;

int h, w, k;

int coord_to_index(int x, int y) {
    return (y - 1) * w + x - 1;
}

//coord1 compared to coord2
int get_delta_x(int x, int x2) {
    if (x > x2) {
        return 1;
    } else if (x < x2) {
        return -1;
    } else {
        return 0;
    }
}

int get_delta_y(int x, int x2) {
    if (x > x2) {
        return 1;
    } else if (x < x2) {
        return -1;
    } else {
        return 0;
    }
}

char get_char(int delta_x, int delta_y) {
    if ((delta_x > 0 && delta_y < 0) || (delta_x < 0 && delta_y > 0)) {
        return '/';
    } else if ((delta_x > 0 && delta_y > 0) || (delta_x < 0 && delta_y < 0)) {
        return '\\';
    } else if (delta_x == 0) {
        return '|';
    } else if (delta_y == 0) {
        return '=';
    } else {
        return 'e';
    }
}

void print_result(vector<char> s) {
    for (int i = 0; i < h * w; i++){
        if (i % w == 0) {
            cout << '\n';
        }
        cout << s[i];
    }
}

tuple<int, int> index_to_coord(int index) {
    return make_tuple(index % w + 1, index / w + 1);
}

bool validate_point(vector<char> shape, int index) {
    if (shape[index - w + 1] == '/' && shape[index - w - 1] == '\\') {return false;}
    if (shape[index - w + 1] == '/' && shape[index - w] == '|') {return false;}
    if (shape[index - w - 1] == '\\' && shape[index - w] == '|') {return false;}

    if (shape[index - w] != '#') {if (shape[index - w + 1] == '/' && shape[index - 1] == '=') {return false;}}
    if (shape[index - w] != '#') {if (shape[index + w + 1] == '\\' && shape[index - 1] == '=') {return false;}}

    if (shape[index + w + 1] == '\\' && shape[index + w - 1] == '/') {return false;}
    if (shape[index + w + 1] == '\\' && shape[index + w] == '|') {return false;}
    if (shape[index + w - 1] == '/' && shape[index + w] == '|') {return false;}

    if (shape[index + w + 1] == '\\' && shape[index + w] == '*') {return false;}
    if (shape[index + w - 1] == '/' && shape[index + w] == '*') {return false;}
    if (shape[index - w + 1] == '/' && shape[index - w] == '*') {return false;}
    if (shape[index - w - 1] == '\\' && shape[index - w] == '*') {return false;}


    /*if (shape[index - w + 1] == '/' && (shape[index - w - 1] == '\\' || shape[index - w] == '|')) {
        return false;
    }


    if ((shape[index + w + 1] == '\\' &&  (shape[index + w - 1] == '/' || shape[index + w] == '|'))) {
        return false;
    }


    /*if ( shape[coord_to_index(x-1, y) == '=']) { // shape[coord_to_index(x+1, y)]
        return false;
    }*/
    
    
    return true;
    
}

vector<char> fill_in(vector<char> shape) {
    bool inside = false;
    for (int i = 0; i < h * w; i++) {
        int x, y;
        tie(x, y) = index_to_coord(i);

        if (x == 1) {
            inside = false;
        }

        char curr_ch = shape[i];

        if (curr_ch != '.') {
            if (curr_ch == '*') {
                if (validate_point(shape, i)) {
                    inside = !inside;
                }
            } else if (curr_ch == '='){

            } else {
                inside = !inside;
            }

        } else {
            if (inside) {
                shape[i] = '#';
            }
        }
    }
    return shape;
}

int main() {
    cin >> h >> w >> k;
    vector<char> shape(h * w, '.');

    //print_result(shape);

    int first_x = -1, first_y = -1;
    int last_x = -1, last_y = -1;

    for (int i = 0; i < k; i++) {
        int x, y;
        cin >> y >> x;

        int current_index = coord_to_index(x, y);
        shape[current_index] = '*';

        //print_result(shape);

        if (first_x < 0) {
            first_x = x, first_y = y;
            last_x = x, last_y = y;
            continue;
        }
        int delta_x, delta_y;

        //cout << x << " " << last_x << " " << y << " " << last_y << "\n";
        delta_x = get_delta_x(x, last_x), delta_y = get_delta_y(y, last_y);

        //cout << delta_x << " " << delta_y << "\n";

        char ch = get_char(delta_x, delta_y);
        //cout << ch << "\n";

        int loop_coord_x = last_x, loop_coord_y = last_y;
        loop_coord_x += delta_x, loop_coord_y += delta_y;
        
        while (true) {
            if (loop_coord_x == x && loop_coord_y == y) {
                break;
            }
            //cout << loop_coord_x << " " << loop_coord_y << " " << coord_to_index(loop_coord_x, loop_coord_y) << "\n";
            shape[coord_to_index(loop_coord_x, loop_coord_y)] = ch;
            loop_coord_x += delta_x, loop_coord_y += delta_y;
        }
        last_x = x;
        last_y = y;
    
    }
    int delta_x = get_delta_x(first_x, last_x), delta_y = get_delta_y(first_y, last_y);
    char ch = get_char(delta_x, delta_y);
    int loop_coord_x = last_x, loop_coord_y = last_y;
    loop_coord_x += delta_x, loop_coord_y += delta_y;
    while (true) {
        if (loop_coord_x == first_x && loop_coord_y == first_y) {
            break;
        }
        //cout << loop_coord_x << " " << loop_coord_y << " " << coord_to_index(loop_coord_x, loop_coord_y) << "\n";
        shape[coord_to_index(loop_coord_x, loop_coord_y)] = ch;
        loop_coord_x += delta_x, loop_coord_y += delta_y;
    }
    
    shape = fill_in(shape);
    print_result(shape);
}

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

.................................

Feedback: Lines are drawn correctly. Incorrect fill character on row 8, col 26: expected '#', got '.'

Test 4 (public)

Verdict: ACCEPTED

input
20 40 14
5 12
5 25
8 28
13 28
...

correct output
.................................

user output

.................................

Feedback: Lines are drawn correctly. Incorrect fill character on row 3, col 27: expected '.', got '#'

Test 5 (public)

Verdict: ACCEPTED

input
20 40 12
3 20
7 16
7 9
11 13
...

correct output
.................................

user output

.................................

Feedback: Lines are drawn correctly. Incorrect fill character on row 7, col 32: expected '.', got '#'

Test 6 (public)

Verdict: ACCEPTED

input
9 35 33
2 3
2 8
4 8
4 5
...

correct output
.................................

user output

.................................

Feedback: Lines are drawn correctly. Incorrect fill character on row 4, col 9: expected '.', got '#'

Test 7 (public)

Verdict: ACCEPTED

input
30 100 69
6 10
6 14
7 14
7 18
...

correct output
.................................

user output

.................................

Feedback: Lines are drawn correctly. Incorrect fill character on row 7, col 19: expected '.', got '#'

Test 8 (public)

Verdict: ACCEPTED

input
40 60 192
11 3
11 5
10 6
11 7
...

correct output
.................................

user output

.................................

Feedback: Lines are drawn correctly. Incorrect fill character on row 2, col 31: expected '.', got '#'

Test 9 (public)

Verdict: ACCEPTED

input
50 100 142
1 1
1 7
1 11
1 14
...

correct output
*=====*===*==*...................

user output

*=====*===*==*...................

Feedback: Lines are drawn correctly. Incorrect fill character on row 2, col 11: expected '#', got '.'

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 39: expected '.', got '#'