Submission #810318

#TimeUsernameProblemLanguageResultExecution timeMemory
810318vjudge1Building 4 (JOI20_building4)C++17
0 / 100
1 ms212 KiB
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

int mtx[333][333];

main() {
#ifdef Home
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // Home
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, k, m;
    cin >> n >> k >> m;
    for(int l, r; m --> 0;) {
        cin >> l >> r;
        if(l < r) {
            for(int i = l; i < min(l + k, r); ++ i) {
                for(int j = i + 1; j <= r; ++ j) {
                    mtx[i][j] = 1;
                }
            }
        } else {
            for(int i = l; i > max(r, l - k); -- i) {
                for(int j = i - 1; j >= r; -- j) {
                    mtx[i][j] = 1;
                }
            }
        }
    }
    for(int i = 1; i <= n; ++ i) {
        for(int j = 1; j <= n; ++ j) {
            mtx[i][j] = (i == j || mtx[i][j]) ? mtx[i][j] : 333;
        }
    }
    for(int k = 1; k <= n; ++ k) {
        for(int i = 1; i <= n; ++ i) {
            for(int j = 1; j <= n; ++ j) {
                mtx[i][j] = min(mtx[i][j], mtx[i][k] + mtx[k][j]);
            }
        }
    }

    int q;
    cin >> q;
    for(int s, t; q --> 0;) {
        cin >> s >> t;
        cout << (mtx[s][t] == 333 ? -1 : mtx[s][t]) << '\n';
    }
}

Compilation message (stderr)

building4.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...