QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#869602 | #5947. Don't Break The Nile | underthetime | 30 ✓ | 249ms | 16748kb | C++14 | 2.9kb | 2025-01-25 11:53:42 | 2025-01-25 11:53:48 |
Judging History
answer
#include <bits/stdc++.h>
bool MemoryST; using namespace std;
#define ll long long
#define mk make_pair
#define open(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define abs(x) (((x) > (0)) ? (x) : (-(x)))
#define lowbit(x) ((x) & (-(x)))
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define BCNT __builtin_popcount
#define cost_time (1e3 * clock() / CLOCKS_PER_SEC)
#define cost_space (abs(&MemoryST - &MemoryED) / 1024.0 / 1024.0) << "MB"
const ll inf = 1e18;
mt19937 rnd(random_device{}());
const int maxn = 1005;
int T, n, m, k, st, ed;
struct Matrix {
int x0, y0, x1, y1;
} a[maxn]; namespace Graph {
struct Edge { int to, nxt, val; } e[maxn * maxn << 1];
int head[maxn], ecnt = 0;
void addEdge(int u, int v, int w) { e[++ ecnt] = Edge { v, head[u], w }, head[u] = ecnt; }
} using namespace Graph;
priority_queue<pair<ll, int> >q; ll dis[maxn]; bool vis[maxn];
void work() {
for (int i = st; i <= ed; i ++) dis[i] = inf, vis[i] = 0;
dis[st] = 0, q.push(mk(0, st));
while (!q.empty()) {
int u = q.top().second; q.pop();
if (vis[u]) continue; vis[u] = 1;
// cout << u << ' ' << dis[u] << '\n';
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to, w = e[i].val;
if (dis[v] > dis[u] + w) {
dis[v] = dis[u] + w;
if (!vis[v]) q.push(mk(-dis[v], v));
}
}
}
}
bool MemoryED; int main() {
auto chkmin = [&](int &a, int b) -> void { a = min(a, b); };
auto disX = [&](int x0, int x1, int _x0, int _x1) -> int {
if (x0 <= _x1 && _x0 <= x1) return 0;
if (x1 < _x0) return _x0 - x1 - 1;
return x0 - _x1 - 1;
}; auto disY = [&](int y0, int y1, int _y0, int _y1) -> int {
if (y0 <= _y1 && _y0 <= y1) return 0;
if (y1 < _y0) return _y0 - y1 - 1;
return y0 - _y1 - 1;
};
scanf("%d", &T); for (int NOW_TEST = 1; NOW_TEST <= T; NOW_TEST ++) {
scanf("%d %d %d", &m, &n, &k), st = 0, ed = k + 1, ecnt = 0;
memset(head, 0, sizeof(head));
for (int i = 1; i <= k; i ++)
scanf("%d %d %d %d", &a[i].x0, &a[i].y0, &a[i].x1, &a[i].y1);
addEdge(st, ed, m);
for (int i = 1; i <= k; i ++) {
auto [x0, y0, x1, y1] = a[i];
addEdge(st, i, x0), addEdge(i, ed, m - x1 - 1);
for (int j = i + 1; j <= k; j ++) {
auto [x0_, y0_, x1_, y1_] = a[j];
int w = max(disX(x0, x1, x0_, x1_), disY(y0, y1, y0_, y1_));
addEdge(i, j, w), addEdge(j, i, w);
}
} work(), printf("Case #%d: %lld\n", NOW_TEST, ::dis[ed]);
}
return 0;
}
/*
1
100 500 9
8 17 39 311
95 254 96 388
15 340 33 396
55 202 91 268
41 88 47 108
60 375 82 425
59 54 79 113
50 65 54 490
74 288 91 305
*/
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3840kb
input:
100 16 419 0 100 500 10 35 322 66 396 68 250 82 420 5 121 42 318 20 375 26 479 94 192 97 233 55 160 63 186 60 145 70 147 50 34 88 61 22 46 32 98 45 158 54 272 100 500 10 8 17 39 311 95 254 96 388 15 340 33 396 55 202 91 268 41 88 47 108 60 375 82 425 59 54 79 113 50 65 54 490 74 288 91 305 7 419 16 ...
output:
Case #1: 16 Case #2: 26 Case #3: 17 Case #4: 37 Case #5: 1 Case #6: 13 Case #7: 34 Case #8: 0 Case #9: 37 Case #10: 12 Case #11: 18 Case #12: 0 Case #13: 0 Case #14: 0 Case #15: 19 Case #16: 0 Case #17: 0 Case #18: 5 Case #19: 0 Case #20: 26 Case #21: 4 Case #22: 35 Case #23: 31 Case #24: 0 Case #25...
result:
ok 100 lines
Subtask #2:
score: 20
Accepted
Test #2:
score: 20
Accepted
time: 249ms
memory: 16748kb
input:
100 84 50179773 32 20 32106308 34 47087131 4 6143627 58 7485509 2 33630407 9 37620847 17 13949314 77 19091045 14 19581218 32 24801601 36 30619147 57 41800856 72 337518 76 12161651 65 48679970 81 48726892 6 1649581 67 4149005 81 23550973 81 35817181 7 28241840 52 28815431 7 8797285 61 11989656 71 204...
output:
Case #1: 14 Case #2: 165 Case #3: 175 Case #4: 99 Case #5: 2 Case #6: 8 Case #7: 93 Case #8: 86 Case #9: 14 Case #10: 0 Case #11: 17 Case #12: 15 Case #13: 35 Case #14: 953 Case #15: 954 Case #16: 30 Case #17: 0 Case #18: 0 Case #19: 0 Case #20: 2 Case #21: 72 Case #22: 117 Case #23: 111 Case #24: 6...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed