QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225487#6995. Moving OnacidlemonRE 0ms3596kbC++172.5kb2023-10-24 18:22:542023-10-24 18:22:55

Judging History

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

  • [2023-10-24 18:22:55]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3596kb
  • [2023-10-24 18:22:54]
  • 提交

answer

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

#define lson (k << 1)
#define rson (k << 1 | 1)
#if LEMON
#define db(x) cout << "function " << __FUNCTION__ << ", line " << __LINE__ << " : " << #x << " " << x << endl;
#else
#define db(x)
#endif

const int mod = 7 + 1e9;
// const int mod = 998244353;
const int N = 3 + 202;

int n, q;
PII a[N];
int b[N];
int d[N][N];

/*
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

*/

void solve(int T) {
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
        b[i] = a[i].first;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            cin >> d[i][j];
        }
    }
    sort(a + 1, a + n + 1);
    vector<array<int, 4>> ve(q);
    vector<int> ans(q);
    int p = 0;
    for (auto &[u, v, w, id] : ve) {
        cin >> u >> v >> w;
        id = p++;
    }
    sort(ve.begin(), ve.end(), [](array<int, 4> &u, array<int, 4> &v) {
        return u[2] < v[2];
    });

    auto update = [&](int k, int w) {
        for (int i = 1; i <= n; ++i) {
            if (b[i] > w) {
                continue;
            }
            for (int j = i + 1; j <= n; ++j) {
                if (b[j] > w) {
                    continue;
                }
                d[j][i] = d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                ve.push_back({i, j});
            }
        }
    };

    p = 1;

    for (auto &[u, v, w, id] : ve) {
        while (p <= n && a[p].first <= w) {
            update(a[p].second, w);
            ++p;
        }
        int z = d[u][v];
        for (int i = 1; i <= n; ++i) {
            if (b[i] > w) {
                continue;
            }
            for (int j = i + 1; j <= n; ++j) {
                if (b[j] > w) {
                    continue;
                }
                if (d[i][j] >= z) {
                    continue;
                }
                z = min(z, d[u][i] + d[i][j] + d[j][v]);
                z = min(z, d[u][j] + d[j][i] + d[i][u]);
            }
        }
        ans[id] = z;
    }
    cout << "Case #" << T << ":\n";
    for (auto &i : ans) {
        cout << i << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve(i);
    }
    return 0;
}

详细

Test #1:

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

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: -100
Runtime Error

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:


result: