| Task: | Monikulmio |
| Sender: | Luhpossu |
| Submission time: | 2025-10-28 13:32:44 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 94 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 94 |
| test | verdict | time | score | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 10 | details |
| #2 | ACCEPTED | 0.00 s | 10 | details |
| #3 | ACCEPTED | 0.01 s | 10 | details |
| #4 | ACCEPTED | 0.00 s | 10 | details |
| #5 | ACCEPTED | 0.00 s | 10 | details |
| #6 | ACCEPTED | 0.00 s | 10 | details |
| #7 | ACCEPTED | 0.00 s | 10 | details |
| #8 | ACCEPTED | 0.00 s | 10 | details |
| #9 | ACCEPTED | 0.00 s | 7 | details |
| #10 | ACCEPTED | 0.01 s | 7 | details |
Compiler report
input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:143:13: warning: 'prevY' may be used uninitialized in this function [-Wmaybe-uninitialized]
143 | drawLine(prevX, prevY, firstX, firstY, grid);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:143:13: warning: 'prevX' may be used uninitialized in this function [-Wmaybe-uninitialized]
input/code.cpp:143:13: warning: 'firstY' may be used uninitialized in this function [-Wmaybe-uninitialized]
input/code.cpp:143:13: warning: 'firstX' may be used uninitialized in this function [-Wmaybe-uninitialized]Code
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>
// #define DEBUG
class Grid {
char *data;
#ifdef DEBUG
int size;
#endif // DEBUG
public:
const int width;
const int height;
Grid(int width, int height) : data(new char[width * height])
#ifdef DEBUG
, size(width * height)
#endif // DEBUG
, width(width), height(height)
{
for (int i = 0; i < width * height; i++) {
data[i] = '#';
}
}
inline int getIndex(int x, int y) {
return (y - 1) * width + x - 1;
}
inline bool inside(int x, int y) {
return x >= 1 && x <= width && y >= 1 && y <= height;
}
char get(int x, int y) {
const int i = getIndex(x, y);
#ifdef DEBUG
if (i >= size) throw std::runtime_error("index: " + std::to_string(i) + ", size: " + std::to_string(size));
if (x > width) throw std::runtime_error("x: " + std::to_string(x) + ", width: " + std::to_string(width));
if (y > height) throw std::runtime_error("y: " + std::to_string(y) + ", height: " + std::to_string(height));
#endif // DEBUG
return data[i];
}
void set(int x, int y, char value) {
const int i = getIndex(x, y);
#ifdef DEBUG
if (i >= size) throw std::runtime_error("index: " + std::to_string(i) + ", size: " + std::to_string(size));
if (x > width) throw std::runtime_error("x: " + std::to_string(x) + ", width: " + std::to_string(width));
if (y > height) throw std::runtime_error("y: " + std::to_string(y) + ", height: " + std::to_string(height));
#endif // DEBUG
data[i] = value;
}
void print() {
for (int y = 1; y <= height; y++) {
for (int x = 1; x <= width; x++) {
std::cout << get(x, y);
}
std::cout << std::endl;
}
}
};
char getDirection(int dx, int dy) {
if (dx == 0) return '|';
if (dy == 0) return '=';
if (dy < 0) {
if (dx < 0) return '\\';
else return '/';
} else {
if (dx < 0) return '/';
else return '\\';
}
}
void drawLine(int prevX, int prevY, int x, int y, Grid& grid) {
int dx = x - prevX;
int dy = y - prevY;
int steps = std::max(std::abs(dx), std::abs(dy));
char direction = getDirection(dx, dy);
for (int step = 0; step < steps - 1; step++) {
if (dx != 0) dx -= dx / std::abs(dx);
if (dy != 0) dy -= dy / std::abs(dy);
grid.set(prevX + dx, prevY + dy, direction);
}
}
void paint(Grid& grid, int x, int y) {
if (!grid.inside(x, y) || grid.get(x, y) != '#') return;
grid.set(x, y, '.');
paint(grid, x - 1, y);
paint(grid, x + 1, y);
paint(grid, x, y - 1);
paint(grid, x, y + 1);
}
void paintBackground(Grid& grid) {
for (int x = 1; x <= grid.width; x++) {
paint(grid, x, 1);
paint(grid, x, grid.height);
}
for (int y = 2; y <= grid.height; y++) {
paint(grid, 1, y);
paint(grid, grid.width, y);
}
}
int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) {
int height, width, lines; std::cin >> height >> width >> lines;
Grid grid(width, height);
bool first = true;
int firstX, firstY, prevX, prevY, x, y;
for (int i = 0; i < lines; i++) {
std::cin >> y >> x;
grid.set(x, y, '*');
if (!first) drawLine(prevX, prevY, x, y, grid);
else {
firstX = x;
firstY = y;
first = false;
}
prevX = x;
prevY = y;
}
drawLine(prevX, prevY, firstX, firstY, grid);
paintBackground(grid);
grid.print();
}
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 |
|---|
| *=====*===*==*................... |
Feedback: Lines are drawn correctly. Incorrect fill character on row 3, col 9: 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 4, col 29: expected '.', got '#'
