QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#463231 | #4363. Branch Assignment | alpha1022 | WA | 944ms | 5744kb | C++14 | 1.5kb | 2024-07-04 16:15:49 | 2024-07-04 16:15:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int N = 5e3;
int n, m, b, k;
vector<pair<int, int>> e0[N + 5], e1[N + 5];
int dis0[N + 5], dis1[N + 5];
void dijkstra(vector<pair<int, int>> *e, int *dis, int s) {
fill_n(dis + 1, n, inf);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
q.emplace(dis[s] = 0, s);
while (!q.empty()) {
auto [d, u] = q.top(); q.pop();
if (d > dis[u]) continue;
for (auto [v, w] : e[u])
if (dis[v] > dis[u] + w)
q.emplace(dis[v] = dis[u] + w, v);
}
}
ll w[N + 5];
pair<ll, int> f[N + 5];
bool check(ll lim) {
for (int i = 1; i <= b; ++i) {
f[i] = {infll, 0};
for (int j = 0; j < i; ++j) {
auto t = f[j]; t.first += (w[i] - w[j]) * (i - j - 1) + lim, ++t.second, f[i] = min(f[i], t);
}
}
return f[b].second >= k;
}
ll ans;
int main() {
scanf("%d%d%d%d", &n, &b, &k, &m);
for (int i = 1; i <= m; ++i) {
int u, v, w; scanf("%d%d%d", &u, &v, &w), e0[u].emplace_back(v, w), e1[v].emplace_back(u, w);
}
dijkstra(e0, dis0, b + 1), dijkstra(e1, dis1, b + 1);
for (int i = 1; i <= b; ++i) w[i] = dis0[i] + dis1[i];
sort(w + 1, w + b + 1);
for (int i = 1; i <= b; ++i) w[i] += w[i - 1];
ll l = 0, r = 1e15, res = 0;
while (l <= r) {
ll mid = (l + r) >> 1;
if (check(mid)) l = mid + 1, res = mid;
else r = mid - 1;
}
check(res), printf("%lld\n", f[b].first - res * k);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4040kb
input:
5 4 2 10 5 2 1 2 5 1 3 5 5 4 5 0 1 5 1 2 3 1 3 2 5 2 4 5 2 1 1 3 4 2
output:
13
result:
ok single line: '13'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4080kb
input:
5 4 2 10 5 2 1 2 5 1 3 5 5 4 5 10 1 5 1 2 3 1 3 2 5 2 4 5 2 1 1 3 4 2
output:
24
result:
ok single line: '24'
Test #3:
score: 0
Accepted
time: 1ms
memory: 4000kb
input:
5 4 3 8 1 5 15 5 1 15 2 5 2 5 2 3 3 5 1 5 3 1 4 5 2 5 4 0
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 0ms
memory: 4068kb
input:
2 1 1 2 1 2 5 2 1 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4328kb
input:
9 4 2 11 1 2 1 2 3 2 3 4 3 4 6 4 6 8 5 8 9 6 9 7 7 7 5 8 5 8 8 7 6 9 6 1 10
output:
304
result:
ok single line: '304'
Test #6:
score: 0
Accepted
time: 944ms
memory: 4528kb
input:
5000 4999 2 9998 1 2 10000 2 1 10000 2 3 10000 3 2 10000 3 4 10000 4 3 10000 4 5 10000 5 4 10000 5 6 10000 6 5 10000 6 7 10000 7 6 10000 7 8 10000 8 7 10000 8 9 10000 9 8 10000 9 10 10000 10 9 10000 10 11 10000 11 10 10000 11 12 10000 12 11 10000 12 13 10000 13 12 10000 13 14 10000 14 13 10000 14 15...
output:
589335814500000
result:
ok single line: '589335814500000'
Test #7:
score: 0
Accepted
time: 913ms
memory: 4928kb
input:
5000 4999 100 9998 1 2 1 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 1 11 12 1 12 13 1 13 14 1 14 15 1 15 16 1 16 17 1 17 18 1 18 19 1 19 20 1 20 21 1 21 22 1 22 23 1 23 24 1 24 25 1 25 26 1 26 27 1 27 28 1 28 29 1 29 30 1 30 31 1 31 32 1 32 33 1 33 34 1 34 35 1 35 36 1 36 37 1 37 38 1 38...
output:
1224510000
result:
ok single line: '1224510000'
Test #8:
score: 0
Accepted
time: 841ms
memory: 5744kb
input:
5000 4900 2000 50000 3116 1995 5417 1801 380 719 4749 13 4103 1175 493 659 596 3035 2098 628 2199 2816 711 3295 5220 4888 4316 153 1007 2136 1990 1365 1579 8062 4076 1263 7023 3114 3756 2785 3695 3175 3364 2302 3474 5739 3062 3705 9620 3815 1026 7712 3991 3582 3049 3245 2397 5834 18 1456 1619 2186 4...
output:
166040058
result:
ok single line: '166040058'
Test #9:
score: 0
Accepted
time: 921ms
memory: 5680kb
input:
5000 4950 2 50000 3669 4840 0 614 3306 0 290 1311 0 2359 2891 0 3497 3550 0 3428 2623 0 1940 3386 0 3650 1263 0 2260 4950 0 1588 3186 0 4498 1773 0 4295 296 0 2956 1009 0 176 3322 0 4509 2130 0 894 4934 0 281 1204 0 1731 14 0 2405 1590 0 1315 635 0 1469 195 0 3651 647 0 82 4604 0 1171 195 0 4275 401...
output:
0
result:
ok single line: '0'
Test #10:
score: -100
Wrong Answer
time: 865ms
memory: 5736kb
input:
5000 4900 4850 50000 2664 4071 4296 612 1817 6511 2292 3113 8392 961 4255 1637 4959 1976 2034 1664 4624 1380 912 3972 8714 1207 2958 2443 3503 729 2610 4920 3996 8547 63 1698 7911 948 4574 1568 1045 4886 5174 3103 4846 1519 875 3369 6492 632 2688 563 1632 3563 588 3929 1553 6982 4707 1623 1425 2762 ...
output:
1182039
result:
wrong answer 1st lines differ - expected: '1182041', found: '1182039'