QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639846 | #1755. Estate Agent | Oxford (Zhiyi Luo, Shangtong Wu, Hugo Domínguez)# | AC ✓ | 4ms | 4256kb | C++20 | 2.4kb | 2024-10-13 23:11:42 | 2024-10-13 23:11:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (auto i = a; i < (b); ++i)
#define repr(i, a, b) for (auto i = (a) - 1; i >= (b); --i)
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define sz(x) (int)((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pii>;
template<class T>
inline bool cmax(T &a, const T& b) {
return a < b ? a = b, 1 : 0;
return b < a ? a = b, 1 : 0;
}
const int inf = 0x3f3f3f3f;
const ll linf = 1e18;
const double dinf = numeric_limits<double>::infinity();
pair<int, vi> hungarian(const vector<vi> &a) {
if (a.empty())
return {0, {}};
int n = sz(a) + 1, m = sz(a[0]) + 1;
vi u(n), v(m), p(m), ans(n - 1);
rep(i, 1, n) {
p[0] = i;
int j0 = 0;
vi dist(m, INT_MAX), pre(m, -1);
vector<bool> done(m + 1);
do {
done[j0]= true;
int i0 = p[j0], j1, delta = INT_MAX;
rep(j, 1, m) if (!done[j]) {
auto cur = a[i0 - 1][j - 1] - u[i0] - v[j];
if (cur < dist[j])
dist[j] = cur, pre[j] = j0;
if (dist[j] < delta)
delta = dist[j], j1 = j;
}
rep(j, 0, m) {
if (done[j])
u[p[j]] += delta, v[j] -= delta;
else
dist[j] -= delta;
}
j0 = j1;
} while (p[j0]);
while (j0) {
int j1 = pre[j0];
p[j0] = p[j1], j0 = j1;
}
}
rep(j, 1, m)
if (p[j])
ans[p[j] - 1] = j - 1;
return {-v[0], ans};
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m;
cin >> n >> m;
vector<vi> cost(n, vi(n, inf));
rep(i, 0, n) {
cost[i][i] = 0;
}
rep(i, 0, m) {
int f, h, a;
cin >> f >> h >> a;
--f;
--h;
cost[f][h] = -a;
}
auto [ans, match] = hungarian(cost);
ans = -ans;
// int ans = -hungarian(cost).first;
cout << fixed << setprecision(10) << double(ans) / 20.0 << '\n';
// rep(i, 0, n) {
// cerr << match[i] << ' ';
// }
// cerr << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
10 90 1 2 134364 1 3 847434 1 4 763775 1 5 255069 1 6 495435 1 7 449491 1 8 651593 1 9 788724 1 10 93859 2 1 28347 2 3 835765 2 4 432767 2 5 762280 2 6 2106 2 7 445387 2 8 721540 2 9 228762 2 10 945271 3 1 901428 3 2 30590 3 4 25445 3 5 541413 3 6 939150 3 7 381204 3 8 216599 3 9 422116 3 10 29040 4...
output:
410034.6000000000
result:
ok found '410034.6000000', expected '410034.6000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4068kb
input:
10 90 1 2 956035 1 3 947828 1 4 56551 1 5 84872 1 6 835499 1 7 735970 1 8 669731 1 9 308136 1 10 605944 2 1 606802 2 3 581204 2 4 158383 2 5 430670 2 6 393532 2 7 723012 2 8 994820 2 9 949396 2 10 544177 3 1 444854 3 2 268241 3 4 35924 3 5 27444 3 6 464894 3 7 318465 3 8 380015 3 9 891790 3 10 52575...
output:
416772.3500000000
result:
ok found '416772.3500000', expected '416772.3500000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
100 9900 1 2 237964 1 3 544229 1 4 369955 1 5 603920 1 6 625720 1 7 65528 1 8 13168 1 9 837469 1 10 259354 1 11 234331 1 12 995645 1 13 470263 1 14 836462 1 15 476353 1 16 639068 1 17 150616 1 18 634861 1 19 868046 1 20 523181 1 21 741252 1 22 671412 1 23 64031 1 24 758231 1 25 591100 1 26 301267 1 ...
output:
4923869.5000000000
result:
ok found '4923869.5000000', expected '4923869.5000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3908kb
input:
100 9900 1 2 236048 1 3 103166 1 4 396058 1 5 154972 1 6 66515 1 7 401591 1 8 917955 1 9 800453 1 10 765163 1 11 221928 1 12 536680 1 13 276682 1 14 172664 1 15 106183 1 16 214400 1 17 927476 1 18 828920 1 19 806653 1 20 800448 1 21 193435 1 22 309850 1 23 626976 1 24 731895 1 25 854649 1 26 880051 ...
output:
4918837.8499999996
result:
ok found '4918837.8500000', expected '4918837.8500000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3900kb
input:
100 9900 1 2 622902 1 3 741787 1 4 795194 1 5 942451 1 6 739899 1 7 922325 1 8 29005 1 9 465623 1 10 943357 1 11 648975 1 12 900901 1 13 113206 1 14 469069 1 15 246573 1 16 543761 1 17 573941 1 18 13114 1 19 216730 1 20 279482 1 21 916346 1 22 765726 1 23 159604 1 24 797147 1 25 138767 1 26 617453 1...
output:
4917583.3499999996
result:
ok found '4917583.3500000', expected '4917583.3500000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 4ms
memory: 4012kb
input:
150 22350 1 2 793340 1 3 821954 1 4 485035 1 5 261621 1 6 451 1 7 662819 1 8 470254 1 9 759731 1 10 373160 1 11 770140 1 12 272698 1 13 801916 1 14 729825 1 15 414006 1 16 538305 1 17 682052 1 18 192985 1 19 553615 1 20 805124 1 21 265521 1 22 803366 1 23 685690 1 24 844283 1 25 335582 1 26 93134 1 ...
output:
7422178.0499999998
result:
ok found '7422178.0500000', expected '7422178.0500000', error '0.0000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 4144kb
input:
150 22350 1 2 323833 1 3 150849 1 4 650935 1 5 72436 1 6 535882 1 7 365689 1 8 57998 1 9 507436 1 10 37495 1 11 433646 1 12 69855 1 13 90713 1 14 424519 1 15 826852 1 16 123802 1 17 223239 1 18 627433 1 19 947709 1 20 577103 1 21 396680 1 22 976256 1 23 46582 1 24 858469 1 25 289609 1 26 144255 1 27...
output:
7422744.7000000002
result:
ok found '7422744.7000000', expected '7422744.7000000', error '0.0000000'
Test #8:
score: 0
Accepted
time: 4ms
memory: 4008kb
input:
150 22350 1 2 226706 1 3 962295 1 4 126331 1 5 704817 1 6 85185 1 7 247441 1 8 999129 1 9 209397 1 10 641869 1 11 459134 1 12 453132 1 13 494983 1 14 192231 1 15 830522 1 16 89565 1 17 234183 1 18 19991 1 19 266767 1 20 407664 1 21 902065 1 22 379075 1 23 113731 1 24 258356 1 25 991603 1 26 63088 1 ...
output:
7417616.0499999998
result:
ok found '7417616.0500000', expected '7417616.0500000', error '0.0000000'
Test #9:
score: 0
Accepted
time: 4ms
memory: 4248kb
input:
150 22350 1 2 463007 1 3 373312 1 4 138539 1 5 866562 1 6 6435 1 7 502782 1 8 898298 1 9 80814 1 10 554271 1 11 616650 1 12 40895 1 13 379019 1 14 703481 1 15 452021 1 16 725066 1 17 157157 1 18 238012 1 19 110947 1 20 506269 1 21 923830 1 22 590429 1 23 774210 1 24 383665 1 25 746095 1 26 101669 1 ...
output:
7419894.4000000004
result:
ok found '7419894.4000000', expected '7419894.4000000', error '0.0000000'
Test #10:
score: 0
Accepted
time: 4ms
memory: 4256kb
input:
150 22350 1 2 571403 1 3 428889 1 4 578091 1 5 206098 1 6 813322 1 7 823589 1 8 653473 1 9 160229 1 10 520669 1 11 327773 1 12 249996 1 13 952817 1 14 996557 1 15 44556 1 16 860161 1 17 603191 1 18 381606 1 19 283618 1 20 674965 1 21 456831 1 22 685862 1 23 661846 1 24 132978 1 25 767838 1 26 982414...
output:
7415207.5000000000
result:
ok found '7415207.5000000', expected '7415207.5000000', error '0.0000000'