QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225490 | #6995. Moving On | acidlemon | TL | 0ms | 3600kb | C++17 | 2.4kb | 2023-10-24 18:24:12 | 2023-10-24 18:24:12 |
Judging History
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]);
}
}
};
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: 3600kb
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:
Case #1: 24 4 12 92424 60 93595 2 40 90101 12 38 56 38 10 90734 8 22 90074 10 2 14 26 24 58 12 50 76 70 6 72 90581 18 6 90186 91689 91107 90515 8 24 24 8 6 8 94 28 20 48 90154 90239 60 38 91193 26 95554 46 80 26 96168 8 40 91980 2 91023 78 90173 60 100 8 98 4 4 92122 2 20 26 94339 6 30 80 90171 54 9...