Submission details
Task:Monikulmio
Sender:lukarantalainen
Submission time:2026-06-05 18:55:33 +0300
Language:C++ (C++20)
Status:READY
Result:0
Feedback
subtaskverdictscore
#10
Test results
testverdicttimescore
#10.00 s0details
#20.00 s0details
#30.00 s0details
#40.00 s0details
#50.00 s0details
#60.00 s0details
#70.00 s0details
#80.00 s0details
#90.00 s0details
#100.00 s0details

Compiler report

input/code.cpp: In function 'void print(int, int, std::vector<std::vector<char> >)':
input/code.cpp:68:12: warning: unused variable 'point' [-Wunused-variable]
   68 |       char point{map[i][j]};
      |            ^~~~~
input/code.cpp:65:14: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   std::system("clear");
      |   ~~~~~~~~~~~^~~~~~~~~

Code

#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <utility>
#include <format>
#include <thread>
#include <cstdlib>
#include <set>
#include <string>

using namespace std::chrono_literals;

enum Direction {
  N = '|',
  NE = '/',
  E = '=',
  SE = '\\',
  S = '|',
  SW = '/',
  W = '=',
  NW = '\\',
  NONE,
};

Direction chars_map[3][3] = {
  {NW, N, NE}, // (0, 0) (0, 1) (0, 2)
  {W, NONE, E}, // (1, 0) (1, 1) (1, 2)
  {SW, S, SE}, // (2, 0) (2, 1) (2, 2)
};

char getChar(std::pair<int, int> v) {
  return static_cast<char>(chars_map[v.first+1][v.second+1]);
}

std::pair<int, int> getVec (const std::pair<int, int> &p1, const std::pair<int, int> &p2) {
  int dx {p2.first-p1.first};
  int dy {p2.second-p1.second};

  return {
      (dx>0)-(dx<0),
      (dy>0)-(dy<0)
    };
}

char getDir(const std::pair<int, int> &p1, const std::pair<int, int> &p2) {
  return getChar(getVec(p1, p2));
}

std::pair<int, int> operator+(const std::pair<int, int> &v1, const std::pair<int, int> &v2){
  return {v1.first+v2.first, v1.second+v2.second};
}

void operator+=(std::pair<int, int> &target, const std::pair<int, int> &add) {
  target = target+add;
} 

std::ostream& operator<<(std::ostream& out, std::pair<int, int> p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
};

void print(int n, int m, std::vector<std::vector<char>> map) {
  std::this_thread::sleep_for(200ms);
  std::system("clear");
  for (int i{}; i<n; ++i) {
    for (int j{}; j<m; ++j) {
      char point{map[i][j]};
      
      std::cout << map[i][j];
    }
    std::cout << "\n";
  }
}

std::vector<std::pair<int, int>> directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
std::set<char> boundaries {
  '|',
  '=',
  '/',
  '\\',
  '*',
  '#',
};

void flood(int n, int m, std::vector<std::vector<char>> &map, std::pair<int, int> node) {
  for (auto d : directions) {
    auto test = node+d;
    if (!boundaries.count(map[test.first][test.second])) {
      map[test.first][test.second] = '#';
      print(n, m, map);
      flood(n, m, map, test);
    }
  }
  return;
}

void solution() {
  std::ifstream input("input.txt");
  std::string line;

  int n{};
  int m{}; 
  int k{};
  std::getline(input, line);
  std::istringstream(line) >> n >> m >> k;

  std::vector<std::vector<char>> map(n, std::vector<char>(m, '.'));
  for (int i{}; i<n; ++i) {
    for (int j{}; j<m; ++j) {
      map[i][j] = '.';
    }
  }

  std::vector<std::pair<int, int>> coords;

  int x, y;
  while (std::getline(input, line)) {
    std::istringstream(line) >> x >> y;
    coords.push_back({x-1, y-1});
  }

  for (size_t i{0}; i<coords.size(); ++i) {
    
    std::pair<int, int> v1{};
    std::pair<int, int> v2{};
    

    if (i+1 == coords.size()) {
      v1 = {coords.back().first, coords.back().second};
      v2 = {coords[0].first, coords[0].second};
    } else {
      v1 = {coords[i].first, coords[i].second};
      v2 = {coords[i+1].first, coords[i+1].second};
    }

    std::pair<int, int> dir = getVec(v1, v2);
    char c = getDir(v1, v2);

    map[v1.first][v1.second] = '*';
    while (true) {
      print(n, m, map);
      v1 += dir;
      if (v1 == v2) {
        break;
      }
      map[v1.first][v1.second] = c;
    }
  }
  std::pair<int, int> p {n/2, m/2};
  flood(n, m, map, p);
  print(n, m, map);
}

int main() {
  solution();

  return 0;
}

Test details

Test 1 (public)

Verdict:

input
8 9 5
5 2
2 5
5 8
7 8
...

correct output
.........
....*....
.../#\...
../###\..
.*#####*.
...

user output
(empty)

Test 2 (public)

Verdict:

input
20 40 4
5 10
5 30
15 30
15 10

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

user output
(empty)

Test 3 (public)

Verdict:

input
20 40 29
8 7
13 2
14 2
9 7
...

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

user output
(empty)

Test 4 (public)

Verdict:

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

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

user output
(empty)

Test 5 (public)

Verdict:

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

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

user output
(empty)

Test 6 (public)

Verdict:

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

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

user output
(empty)

Test 7 (public)

Verdict:

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

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

user output
(empty)

Test 8 (public)

Verdict:

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

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

user output
(empty)

Test 9 (public)

Verdict:

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

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

user output
(empty)

Test 10 (public)

Verdict:

input
100 100 1000
10 1
4 7
1 4
1 9
...

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

user output
(empty)