QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225463#6995. Moving OnacidlemonTL 1ms3436kbC++172.4kb2023-10-24 17:48:522023-10-24 17:48:53

Judging History

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

  • [2023-10-24 17:48:53]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3436kb
  • [2023-10-24 17:48:52]
  • 提交

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];
int dd[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];
            dd[i][j] = 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) {
        vector<PII> ve;
        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});
            }
        }
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (b[i] <= w && b[j] <= w) {
                    continue;
                }
                for (auto &[u, v] : ve) {
                    dd[j][i] = dd[i][j] = min(dd[i][j], dd[i][u] + d[u][v] + dd[v][j]);
                }
            }
        }
    };

    p = 1;

    for (auto &[u, v, w, id] : ve) {
        while (p <= n && a[p].first <= w) {
            update(a[p].second, w);
            ++p;
        }
        ans[id] = dd[u][v];
    }
    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: 1ms
memory: 3436kb

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
Time Limit Exceeded

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: