38162023-03-03 09:43:17ZsofiaKeresztelyRácsháló gráfcpp14Accepted 50/508ms4340 KiB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second

vector<vector<int> > d;

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    d.resize(n*m+1, vector<int>(n*m+1));
    for (int i=0; i<n*m; i++){
        for (int j=i; j<n*m; j++){
            d[i+1][j+1] = abs(i % m - j % m) + abs(i / m - j / m);
            d[j+1][i+1] = abs(i % m - j % m) + abs(i / m - j / m);
        }
    }
    while (k--){
        int a, b, op = 0;
        cin >> a >> b;
        for (int i=1; i<=n*m; i++){
            for (int j=i; j<=n*m; j++){
                d[i][j] = min(d[i][j], min(d[i][a] + d[j][b] + 1, d[i][b] + d[j][a] + 1));
                d[j][i] = d[i][j];
                op = max(op, d[i][j]);
            }
        }
        cout << op << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/08ms2436 KiB
3Accepted2/23ms2368 KiB
4Accepted2/23ms2352 KiB
5Accepted2/23ms2424 KiB
6Accepted2/23ms2428 KiB
7Accepted2/23ms2468 KiB
8Accepted2/23ms2672 KiB
9Accepted2/23ms2932 KiB
10Accepted2/23ms3104 KiB
11Accepted2/23ms3216 KiB
12Accepted2/24ms3500 KiB
13Accepted3/34ms3268 KiB
14Accepted3/33ms3492 KiB
15Accepted3/34ms3744 KiB
16Accepted3/33ms3476 KiB
17Accepted3/34ms3788 KiB
18Accepted3/33ms3608 KiB
19Accepted3/33ms3576 KiB
20Accepted3/33ms3808 KiB
21Accepted3/33ms3836 KiB
22Accepted3/38ms4340 KiB