Submission details
Task:Hypyt
Sender:Luhpossu
Submission time:2025-11-03 20:08:29 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:99:22: error: no match for 'operator<<' (operand types are '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> >'})
   99 |     cout << "time: " << 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::basic_ostream<char>
In file included from /usr/include/c++/11/iostream:39,
                 from input/code.cpp:2:
/usr/include/c++/11/ostream:108:7: note: candidate: 'std::basic_ostream<_CharT, _...

Code

#include <cstring>
#include <iostream>
#include <vector>
#include <chrono>

using namespace std;

using in = int;
using pi = pair<in, in>;

vector<in> *rows;
vector<in> *columns;
bool **checked;

int min;

// 127 ms
// 101 ms

char find(vector<pi>& next, pi pos, pi end) {
    if (end.first == pos.first || end.second == pos.second) return 1;

    if (checked[pos.second][pos.first]) return false;
    checked[pos.second][pos.first] = true;

    for (in x : rows[pos.second]) {
        if (x == end.first) return 2;
        if (x == pos.first) continue;
        next.push_back({ x, pos.second });
    }

    for (in y : columns[pos.first]) {
        if (y == end.second) return 2;
        if (y == pos.second) continue;
        next.push_back({ pos.first, y });
    }

    return false;
}

int search(pi start, pi end, int height, int width) {
    if (start.first == end.first && start.second == end.second) return 0;

    std::vector<pi> next{start};
    int depth = 0;

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

    while (next.size()) {
        std::vector<pi> copy;
        copy.reserve(next.size() * 4);

        for (pi pos : next) {
            int sus = find(copy, pos, end);
            if (sus) return depth + sus;
        }

        next = copy;
        depth++;
    }

    return -1;
}

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

    rows = new vector<in>[height];
    columns = new vector<in>[width];
 
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            char c; cin >> c;
            if (c == '.') {
                rows[y].push_back(x);
                columns[x].push_back(y);
            }
        }
    }

    checked = new bool*[height];
    for (int i = 0; i < height; i++) checked[i] = new bool[width];

    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 }});
    }

    auto startTime = chrono::high_resolution_clock::now();
    for (auto [start, end] : queries) {
        int sus = search(start, end, height, width);
        cout << sus << endl;
    }
    auto endTime = chrono::high_resolution_clock::now();

    cout << "time: " << endTime - startTime << endl;
}