QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620744 | #7185. Poor Students | Tomorrow | TL | 3342ms | 5552kb | C++17 | 3.3kb | 2024-10-07 20:57:14 | 2024-10-07 20:57:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define C const
#define U unsigned
#define SC static
#define CE constexpr
#define TL template
#define TN typename
#define OP operator
#define pb push_back
#define ft first
#define sd second
#define mi (l + (r - l) / 2)
#define TTT TL<TN T = I>
#define TTI TL<TN It>
#define BE(v) v.begin(), v.end()
#define VD void
#define BL bool
#define CH char
#define I int
#define LL long long
#define II __int128
#define D double
#define STR string
using PII = pair<I, I>;
TTT using V = vector<T>;
TTT using Heap = priority_queue<T, V<T>, greater<T>>;
#define FORX(v) for(auto& x : v)
#define FOR(i, b, e) for(auto i = b, _e = (decltype(i))e;i != _e; ++i)
#define FORR(i, b, e) for(auto i = b, _e = (decltype(i))e;i != _e; --i)
#define FORV(v, i) for (I i = 0, _n = v.size(), x = _n ? v[0] : 0;i < _n;x = v[++i])
#define FUNC(T, f, ...) function<T(__VA_ARGS__)> f = [&](__VA_ARGS__)->T
#define DR(T, ...) T __VA_ARGS__; R(__VA_ARGS__);
TTT VD R(T& x) { cin >> x; }
TTT T R() { DR(T, x); return x; }
TL<TN T, TN... A> VD R(T& x, A&... a) { R(x), R(a...); }
CE CH LF = '\n', SP = ' ';
TL<CH s = LF> VD W() { cout << s; }
TL<CH s = LF, TN T> VD W(C T& x) { cout << x << s; }
TL<CH s = LF, TN T, TN... A> VD W(C T& x, C A&... a) { W<SP>(x), W<s>(a...); }
TTT CE T inf() { return numeric_limits<T>::max() / 2; }
TTT VD setmin(T& a, C T& b) { if (b < a)a = b; }
TTT VD setmax(T& a, C T& b) { if (a < b)a = b; }
TL<TN T, TN S> struct MCMF//Minimum Cost Maximum Flow, O(m * logm * mf)
{
struct EG { I t; T c; S v; };
I n; V<V<I>> e; V<EG> a; V<S> h, ds; V<I> vs; V<I> r;
MCMF(I n) :n(n), e(n), h(n, inf<S>()), ds(n), vs(n), r(n) {}
VD ade(I u, I v, T w, S x) { e[u].pb(a.size()), a.pb({ v,w,x }); }
VD add(I u, I v, T w, S x) { ade(u, v, w, x), ade(v, u, 0, -x); }
VD spfa(I s)
{
V<I> q{ s }; I hd = 0;
h[s] = 0; vs[s] = 1;
while (hd < q.size())
{
I p = q[hd++]; vs[p] = 0;
FORX(e[p])
{
EG& eg = a[x];
if (!eg.c || h[eg.t] <= h[p] + eg.v)continue;
h[eg.t] = h[p] + eg.v;
if (!vs[eg.t])vs[eg.t] = 1, q.pb(eg.t);
}
}
}
I dijkstra(I s, I t)
{
Heap<pair<S, I>> q;
fill(BE(ds), inf<S>()); fill(BE(vs), 0);
q.push({ 0,s }); ds[s] = 0;
while (q.size())
{
I p = q.top().sd; q.pop();
if (vs[p]++)continue;
FORX(e[p])
{
I t = a[x].t; S v = a[x].v + h[p] - h[t];
if (!a[x].c || ds[t] <= ds[p] + v)continue;
ds[t] = ds[p] + v, r[t] = x;
q.push({ ds[t],t });
}
}
return vs[t];
}
pair<T, S> OP()(I s, I t)
{
spfa(s); T ansf = 0; S ansv = 0;
while (dijkstra(s, t))
{
T mc = inf<T>();
FOR(i, 0, n)h[i] += ds[i];
for (I p = t; p != s;p = a[r[p] ^ 1].t)
setmin(mc, a[r[p]].c);
for (I p = t; p != s;p = a[r[p] ^ 1].t)
a[r[p]].c -= mc, a[r[p] ^ 1].c += mc;
ansf += mc, ansv += mc * h[t];
}
return { ansf, ansv };
}
};
VD test()
{
DR(I, n, k);
++n;++k;
MCMF<I, I> mf(n + k);
FOR(i, 1, n)
{
mf.add(0, i, 1, 0);
FOR(j, 1, k)mf.add(i, n + j, 1, R());
}
FOR(i, 1, k)mf.add(n + i, n, R(), 0);
W(mf(0, n).sd);
}
I main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if (fopen("test.in", "r"))
{
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
}
I t = 1;
// R(t);
while (t--)test();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
6 2 1 2 1 3 1 4 1 5 1 6 1 7 3 4
output:
12
result:
ok answer is '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
3 3 1 2 3 2 4 6 6 5 4 1 1 1
output:
8
result:
ok answer is '8'
Test #3:
score: 0
Accepted
time: 118ms
memory: 3828kb
input:
1000 10 734 303 991 681 755 155 300 483 702 442 237 256 299 675 671 757 112 853 759 233 979 340 288 377 718 199 935 666 576 842 537 363 592 349 494 961 864 727 84 813 340 78 600 492 118 421 478 925 552 617 517 589 716 7 928 638 258 297 706 787 266 746 913 978 436 859 701 951 137 44 815 336 471 720 2...
output:
92039
result:
ok answer is '92039'
Test #4:
score: 0
Accepted
time: 3342ms
memory: 5552kb
input:
5000 10 14 114 254 832 38 904 25 147 998 785 917 694 750 372 379 887 247 817 999 117 802 15 799 515 316 42 69 247 95 144 727 398 509 725 682 456 369 656 693 955 923 1 681 631 962 826 233 963 289 856 165 491 488 832 111 950 853 791 929 240 509 843 667 970 469 260 447 477 161 431 514 903 627 236 144 3...
output:
461878
result:
ok answer is '461878'
Test #5:
score: -100
Time Limit Exceeded
input:
10000 10 307 205 765 487 504 526 10 581 234 583 448 443 39 992 976 363 335 588 588 169 920 787 896 822 47 358 230 631 136 299 141 159 414 852 922 945 513 76 111 189 616 104 83 792 24 68 164 975 615 472 150 108 848 517 7 153 107 283 452 165 94 370 910 662 226 720 975 214 324 407 636 65 963 859 590 3 ...