Submission details
Task:Hypyt
Sender:Luhpossu
Submission time:2025-10-31 16:55:37 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:110:10: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'std::common_type<std::chrono::duration<long int, std::ratio<1, 1000000000> >, std::chrono::duration<long int, std::ratio<1, 1000000000> > >::type' {aka 'std::chrono::duration<long int, std::ratio<1, 1000000000> >'})
  110 |     cout << endTime - startTime << endl;
      |     ~~~~ ^~ ~~~~~~~~~~~~~~~~~~~
      |     |               |
      |     |               std::common_type<std::chrono::duration<long int, std::ratio<1, 1000000000> >, std::chrono::duration<long int, std::ratio<1, 1000000000> > >::type {aka std::chrono::duration<long int, std::ratio<1, 1000000000> >}
      |     std::ostream {aka std::basic_ostream<char>}
In file included from /usr/include/c++/11/iostream:39,
                 from input/code.cpp:6:
/usr/include/c++/11/ostream:108:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__o...

Code

#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <unistd.h>
#include <vector>

using namespace std;
using pi = pair<int, int>;

vector<int> *baseRows;
vector<int> *baseColumns;

vector<int> *copyRows;
vector<int> *copyColumns;

constexpr int NOT_FOUND = 10000;

void findPath(int **path, int depth, pi pos, bool row, pi target, int *min) {
    path[pos.first][pos.second] = depth;

    int whenExact = depth - 1;
    if (whenExact >= *min) return;

    if (pos.first == target.first && pos.second == target.second) {
        *min = whenExact;
        return;
    }

    if (depth >= *min) return;
    if (pos.first == target.first || pos.second == target.second) {
        *min = depth;
        return;
    }

    if (depth + 1 >= *min) return;

    vector<int> list = row ? baseRows[pos.second] : baseColumns[pos.first];
    if (list.empty()) return;

    for (int i : list) {
        pi pos2;
        if (row) pos2 = { i, pos.second };
        else pos2 = { pos.first, i };

        int found = path[pos2.first][pos2.second];

        if (found <= depth + 1) continue;

        findPath(path, depth + 1, pos2, !row, target, min);
    }
}

int main(int argc, char *argv[]) {
    int height, width, count; cin >> height >> width >> count;

    baseRows = new vector<int>[height];
    baseColumns = new vector<int>[width];

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            char c; cin >> c;

            if (c == '.') {
                baseRows[y].push_back(x);
                baseColumns[x].push_back(y);
            }
        }
    }
    
    vector<pair<pi, pi>> queries;

    for (int i = 0; i < count; i++) {
        int y1, x1, y2, x2; cin >> y1 >> x1 >> y2 >> x2; 

        queries.push_back({ { x1 - 1, y1 - 1 }, { x2 - 1, y2 - 1 } });
    }

    int **path = new int*[width];

    for (int i = 0; i < width; i++) {
        int *arr = new int[height];
        path[i] = arr;
    }

    auto startTime = chrono::high_resolution_clock::now();
    for (auto [start, end] : queries) {
        int min = NOT_FOUND;

        for (int i = 0; i < width; i++)
            memset((void*)(path[i]), 127, height * sizeof(int));

        for (int i = 0; i < height; i++)
            sort(baseRows[i].begin(), baseRows[i].end(), [end](int p1, int p2) -> bool { return abs(p1 - end.first) < abs(p2 - end.first); });

        for (int i = 0; i < width; i++)
            sort(baseColumns[i].begin(), baseColumns[i].end(), [end](int p1, int p2) -> bool { return abs(p1 - end.second) < abs(p2 - end.second); });
        
        findPath(path, 1, start, true, end, &min);
        findPath(path, 1, start, false, end, &min);

        if (min == NOT_FOUND) min = -1;

        cout << min << endl;
    }
    auto endTime = chrono::high_resolution_clock::now();

    cout << endTime - startTime << endl;
}