QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#726683#6995. Moving OnacidlemonAC ✓602ms4088kbC++172.0kb2024-11-09 05:33:102024-11-09 05:33:16

Judging History

你现在查看的是最新测评结果

  • [2024-11-09 05:33:16]
  • 评测
  • 测评结果:AC
  • 用时:602ms
  • 内存:4088kb
  • [2024-11-09 05:33:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;

struct Lemon {
    Lemon() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} lemon;

#define lson (k << 1)
#define rson (k << 1 | 1)

const int mod = 7 + 1e9;
// const int mod = 998244353;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
#if LEMON
const int N = 3 + 111;
#else
#define endl '\n'
const int N = 3 + 200;
#endif

int d[N][N], n, q;

void solve() {
    cin >> n >> q;

    vector<PII> a(n);
    vector<array<int, 4>> query(q);

    for (int i = 0; i < n; ++i) {
        a[i].first = i + 1;
        cin >> a[i].second;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            cin >> d[i][j];
        }
    }

    for (int i = 0; i < q; ++i) {
        query[i][0] = i;
        cin >> query[i][1] >> query[i][2] >> query[i][3];
    }

    sort(a.begin(), a.end(), [](PII x, PII y) {
        return x.second < y.second;
    });
    sort(query.begin(), query.end(), [](array<int, 4> x, array<int, 4> y) {
        return x[3] < y[3];
    });

    int k = 0;
    for (auto& [id, u, v, w] : query) {
        // cout << id << " " << u << " " << v << " " << w << endl;
        while (k < a.size() && a[k].second <= w) {
            // cout << " " << a[k].first << " " << a[k].second << endl;
            for (int i = 1; i <= n; ++i) {
                for (int j = 1; j <= n; ++j) {
                    d[i][j] = min(d[i][j], d[i][a[k].first] + d[a[k].first][j]);
                }
            }
            ++k;
        }
        w = d[u][v];
    }
    sort(query.begin(), query.end());
    for (auto i : query) {
        cout << i.back() << endl;
    }
    cout << endl;
}

int main() {
    int T;
    cin >> T;
    for (int t = 1; t <= T; ++t) {
        cout << "Case #" << t << ":" << endl;
        solve();
    }
    return 0;
}
/*
1
3 6
1 2 3
0 1 3
1 0 1
3 1 0
1 1 1
1 2 1
1 3 1
1 1 2
1 2 2
1 3 2

*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

1
3 6
1 2 3
0 1 3
1 0 1
3 1 0
1 1 1
1 2 1
1 3 1
1 1 2
1 2 2
1 3 2

output:

Case #1:
0
1
3
0
1
2


result:

ok 8 tokens

Test #2:

score: 0
Accepted
time: 602ms
memory: 4088kb

input:

50
195 19034
11 94 57 66 65 84 55 59 76 31 57 10 88 41 34 61 40 22 40 53 5 35 64 100 77 74 16 92 17 68 22 86 95 55 99 10 35 37 9 7 14 75 19 69 27 64 22 21 62 83 74 19 50 61 42 26 67 19 20 73 95 98 81 39 93 13 63 47 68 37 39 73 80 83 76 19 10 27 74 24 97 3 2 27 50 96 37 77 67 20 81 35 24 68 70 27 21 ...

output:

Case #1:
90188
90734
90911
91955
90188
93595
90205
90151
90101
90305
90837
254
90218
90953
90701
164
90187
90074
455
90391
90241
90148
288
495
90268
90383
90146
91146
90181
90198
94346
528
60
90186
90990
90220
90515
90353
90271
90298
245
90377
90140
90940
28
90125
90334
90154
90239
90856
90649
90407...

result:

ok 971923 tokens