Submission details
Task:Hypyt
Sender:Lytsky
Submission time:2025-11-04 23:07:54 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:120:81: error: conversion from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to non-scalar type 'std::pair<int, std::vector<std::pair<std::vector<int>, std::vector<int> > > >' requested
  120 |             pair<int, vector<pair<vector<int>,vector<int>>>> dist = d[y1-1][y2-1];
      |                                                                                 ^
input/code.cpp:121:22: error: no match for 'operator>=' (operand types are 'std::pair<int, std::vector<std::pair<std::vector<int>, std::vector<int> > > >' and 'double')
  121 |             if (dist >= 1e9) cout << -1 << endl;
      |                 ~~~~ ^~ ~~~
      |                 |       |
      |                 |       double
      |                 std::pair<int, std::vector<std::pair<std::vector<int>, std::vector<int> > > >
In file included from /usr/include/c++/11/regex:63,
                 from /usr/include/x86_64-linux-gnu/c++...

Code

#include <bits/stdc++.h>

using namespace std;

bool contains(vector<int> v, int num) {
    for (auto i : v) {
        if (i == num) {
            return true;
        }
    }
    return false;
}

int main() {
    int n, m, q, y1, x1, y2, x2;
    string row;
    cin >> n >> m >> q;
    vector<string> grid;
    vector<int> nodesInColumns[m];
    vector<vector<pair<int, pair<vector<int>, vector<int>>>>> row_kaaret(n);
    vector<vector<vector<vector<int>>>> paths(n);
    vector<vector<int>> d(n);
    for (int index = 0; index < n; index++) {
        vector<pair<int,pair<vector<int>,vector<int>>>> v(n, {0, {}});
        row_kaaret[index] = v;
        vector<int> j(n);
        d[index] = j;
        vector<vector<vector<int>>> s;
        for (int i = 0; i < n; i++) { 
            vector<vector<int>> M(m);
            s.push_back(M);
        }
        paths[index] = s;
    }

    for (int index = 0; index < n; index++) {
        cin >> row;
        grid.push_back(row);
        for (int col = 0; col < m; col++) {
            if (grid[index][col] == '.') {
                nodesInColumns[col].push_back(index);
            }
        }
    }
    for (int index = 0; index < m; index++) {
        for (auto node : nodesInColumns[index]) {
            for (auto node2 : nodesInColumns[index]) {
                if (node != node2) {
                    row_kaaret[node][node2].first = 1;
                    row_kaaret[node][node2].second.first.push_back(index);
                    row_kaaret[node][node2].second.second.push_back(index);
                    paths[node2][node][index].push_back(index);
                    paths[node][node2][index].push_back(index);
                }
            }
        }
    }
    //floyd
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) d[i][j] = 0;
            else if (row_kaaret[i][j].first != 0) {
                d[i][j] = row_kaaret[i][j].first;
                pair<vector<int>,vector<int>> p = row_kaaret[i][j].second;
            }
            else d[i][j] = 1e9;
        }
    }
    /*for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << "( ";
            for (auto x : row_kaaret[i][j].second.first) {
                cout << x << " ";
            }
            cout << ")";
        }
        cout << endl;
    }*/
    vector<vector<int>> clearing(n);
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (d[i][j] > d[i][k] + d[k][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                    row_kaaret[i][j].second.first = row_kaaret[i][k].second.first;
                    row_kaaret[i][j].second.second = row_kaaret[k][j].second.second;
                    pair<vector<int>,vector<int>> p;
                    p.first = row_kaaret[i][k].second.first;
                    p.second = row_kaaret[k][j].second.second;
                    paths[i][j] = clearing;
                    paths[j][i] = clearing;
                    for (auto x : row_kaaret[i][k].second.first) { 
                        paths[i][j][x] = row_kaaret[k][j].second.second;
                    }
                    for (auto x : row_kaaret[k][j].second.second) { 
                        paths[j][i][x] = row_kaaret[i][k].second.first;
                    }
                } else if (d[i][j] == d[i][k] + d[k][j]) {
                    row_kaaret[i][j].second.first.insert(row_kaaret[i][j].second.first.end(), row_kaaret[i][k].second.first.begin(), row_kaaret[i][k].second.first.end());
                    row_kaaret[i][j].second.second.insert(row_kaaret[i][j].second.second.end(), row_kaaret[k][j].second.second.begin(), row_kaaret[k][j].second.second.end());
                    //pair<vector<int>,vector<int>> p;
                    //p.first = row_kaaret[i][k].second.first;
                    //p.second = row_kaaret[k][j].second.second;
                    for (auto x : row_kaaret[i][k].second.first) { 
                        paths[i][j][x].insert(paths[i][j][x].begin(),row_kaaret[k][j].second.second.begin(),row_kaaret[k][j].second.second.end());
                    }
                    for (auto x : row_kaaret[k][j].second.second) { 
                        paths[j][i][x].insert(paths[j][i][x].begin(),row_kaaret[i][k].second.first.begin(),row_kaaret[i][k].second.first.end());
                    }
                }
            }
        }
    }
    //kyselyt
    for (int index = 0; index < q; index++) {
        cin >> y1 >> x1 >> y2 >> x2;
        if (y1 == y2 && x1 == x2) cout << 0 << endl;
        else if (y1 == y2 || x1 == x2) cout << 1 << endl;
        else {
            pair<int, vector<pair<vector<int>,vector<int>>>> dist = d[y1-1][y2-1];
            if (dist >= 1e9) cout << -1 << endl;
            else {
                int a = 2;
                if (!paths[y1-1][y2-1][x1-1].empty()) {
                    if (contains(paths[y1-1][y2-1][x1-1], x2-1)) {
                        a--;
                    }
                    a--;
                }
                else if (!paths[y2-1][y1-1][x2-1].empty()) {
                    if (contains(paths[y2-1][y1-1][x2-1], x1-1)) a--;
                    a--;
                }
                cout << dist + dist-1 + a << endl; 
            }
        }
    }
}