QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#538169 | #8936. Team Arrangement | ucup-team4757# | TL | 665ms | 106996kb | C++14 | 4.5kb | 2024-08-31 08:26:46 | 2024-08-31 08:26:48 |
Judging History
answer
#include <bits/stdc++.h>
const int MAXN = 155;
const int INF = 1e4;
int ans = - INT_MAX, tmp = 0;
namespace MCMF {
using namespace std;
const int MAXN = 500;
const int32_t INF = 10000; // Don't Be Too Large
struct Edge {
int u, v, nxt;
int32_t f, w;
} E[MAXN << 4];
int H[MAXN], tot = 1;
inline void Add_Edge (const int u, const int v, const int32_t f, const int32_t w) {
E[++ tot] = {u, v, H[u], f, + w}, H[u] = tot;
E[++ tot] = {v, u, H[v], 0, - w}, H[v] = tot;
}
int32_t Pre[MAXN];
int fa[MAXN], fe[MAXN], Cir[MAXN], Tag[MAXN];
int Now = 0, S = 145, T = 148;
inline void Init_ZCT (const int x, const int e, int Nod = 1) {
fe[x] = e, fa[x] = E[e].u, Tag[x] = Nod;
for (int i = H[x]; i; i = E[i].nxt)
if (Tag[E[i].v] != Nod && E[i].f) Init_ZCT (E[i].v, i, Nod);
}
inline int32_t Sum (const int x) {
if (Tag[x] == Now) return Pre[x];
Tag[x] = Now, Pre[x] = Sum (fa[x]) + E[fe[x]].w;
return Pre[x];
}
inline int32_t Push_Flow (const int x) {
int rt = E[x].u, lca = E[x].v, Cnt = 0, Del = 0, P = 2;
++ Now;
while (rt) Tag[rt] = Now, rt = fa[rt];
while (Tag[lca] != Now) Tag[lca] = Now, lca = fa[lca];
int32_t F = E[x].f, Cost = 0;
for (int u = E[x].u; u != lca; u = fa[u]) {
Cir[++ Cnt] = fe[u];
if (F > E[fe[u]].f)
F = E[fe[u]].f, Del = u, P = 0;
}
for (int u = E[x].v; u != lca; u = fa[u]) {
Cir[++ Cnt] = fe[u] ^ 1;
if (F > E[fe[u] ^ 1].f)
F = E[fe[u] ^ 1].f, Del = u, P = 1;
}
Cir[++ Cnt] = x;
for (int i = 1; i <= Cnt; ++ i)
Cost += F * E[Cir[i]].w, E[Cir[i]].f -= F, E[Cir[i] ^ 1].f += F;
if (P == 2) return Cost;
int u = E[x].u, v = E[x].v;
if (P == 1) swap (u, v);
int Lste = x ^ P, Lstu = v, Tmp;
while (Lstu != Del) {
Lste ^= 1, -- Tag[u];
swap (fe[u], Lste);
Tmp = fa[u], fa[u] = Lstu, Lstu = u, u = Tmp;
}
return Cost;
}
int32_t MinC = 0;
inline int32_t Simplex () {
Add_Edge (T, S, INF, - INF);
Init_ZCT (T, 0, ++ Now);
Tag[T] = ++ Now, fa[T] = 0;
bool Run = 1;
while (Run) {
Run = 0;
for (int i = 2; i <= tot; ++ i)
if (E[i].f && E[i].w + Sum (E[i].u) - Sum (E[i].v) < 0)
MinC += Push_Flow (i), Run = 1;
}
MinC += E[tot].f * INF;
return E[tot].f;
}
}
struct nod {
std::vector <int> k;
int32_t w;
inline bool operator < (const nod &a) const {
return w < a.w;
}
};
std::vector <int> v;
std::vector <nod> t;
int l[MAXN], r[MAXN], N;
int w[MAXN], stu[MAXN], tea[MAXN];
inline int Calc () {
int ret = 0;
for (auto i : v) ret += w[i];
return ret;
}
inline void Add () {
t.push_back ({v, Calc ()});
}
int n;
int c1, c2, c3, c4, c5;
inline int G (const int x, const int f = 0) {
return x + f * 60;
}
inline void Solve () {
if ((tmp = Calc ()) <= ans) return ++ c1, void ();
for (auto i : v) if (stu[i] < i) return ++ c2, void ();
for (int i = 1; i <= n; ++ i) tea[i] = 0;
for (auto i : v) tea[i] = 1;
for (int i = 1; i <= n; ++ i) tea[i] += tea[i - 1];
for (int i = 1; i <= n; ++ i)
if (tea[r[i]] - tea[l[i] - 1] == 0)
return ++ c3, void ();
memset (MCMF::H, 0, sizeof MCMF::H);
memset (MCMF::Pre, 0, sizeof MCMF::Pre);
MCMF::tot = 1;
// Dinic::tot = 1;
for (int i = 1; i <= n; ++ i) MCMF::Add_Edge (MCMF::S, G (i, 0), 1, 0);
for (int i = 0; i < (int) v.size (); ++ i) MCMF::Add_Edge (G (i + 1, 1), MCMF::T, v[i], 0);
for (int i = 1; i <= n; ++ i)
for (int k = 0; k < (int) v.size (); ++ k)
if (l[i] <= v[k] && v[k] <= r[i])
MCMF::Add_Edge (G (i, 0), G (k + 1, 1), 1, 0);
int MaxF = MCMF::Simplex ();
if (MaxF == n) ans = tmp, ++ c4;
else ++ c5;
}
inline void dfs (const int n, const int lst = 1) {
if (n == 0) return Add (), void ();
for (int i = lst; i <= n; ++ i) v.push_back (i), dfs (n - i, i), v.pop_back ();
}
inline void solve () {
std::sort (t.begin (), t.end ());
for (int i = t.size () - 1; i >= 0; -- i) {
v = t[i].k, Solve ();
if (ans == t[i].w) return ;
}
}
int main () {
std::cin >> n;
for (int i = 1; i <= n; ++ i) std::cin >> l[i] >> r[i], ++ stu[l[i]], -- stu[r[i] + 1];
for (int i = 1; i <= n; ++ i) std::cin >> w[i];
for (int i = 1; i <= n; ++ i) stu[i] += stu[i - 1];
dfs (n), solve ();
std::cout << (ans == - INT_MAX ? "impossible" : std::to_string (ans)) << '\n';
std::cerr << t.size () << ' ' << c1 << ' ' << c2 << ' ' << c3 << ' ' << c4 << ' ' << c5 << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
3 2 3 1 2 2 2 4 5 100
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
3 1 3 3 3 2 3 1 1 100
output:
100
result:
ok single line: '100'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
3 2 3 1 2 2 2 -100 -200 100000
output:
-300
result:
ok single line: '-300'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
9 1 4 2 5 3 4 1 5 1 1 2 5 3 5 1 3 1 1 1 1 1 1 1 1 1 1 1
output:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
14 3 3 1 2 2 3 2 3 2 3 1 1 2 3 1 3 3 3 1 3 1 3 1 2 2 3 1 3 -9807452 -9610069 4156341 2862447 6969109 -7245265 -2653530 -5655094 6467527 -6872459 3971784 7312155 9766298 -2719573
output:
-16558567
result:
ok single line: '-16558567'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
14 1 2 1 4 2 3 3 5 4 5 2 5 2 4 2 4 1 2 3 4 1 5 2 4 1 1 4 5 -13763 -7354207 1096407 -9063321 -4824546 -6275546 1258145 -5272834 -8631107 3581157 2320771 -7714508 8446625 -6816167
output:
-2673021
result:
ok single line: '-2673021'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
14 2 3 4 4 1 7 3 6 3 4 1 1 1 4 4 7 3 7 1 7 2 3 6 6 1 1 3 6 2923142 1686477 640352 2848353 9202543 -4441381 4866381 -3610520 8124124 -1372894 1111310 -7538627 466143 9937961
output:
5939733
result:
ok single line: '5939733'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
14 1 7 1 2 8 8 1 1 7 8 6 9 7 8 1 4 6 9 3 3 1 1 3 7 5 8 4 8 -7139089 6365816 -9893288 5936146 -2803918 -4961415 1495365 -2564851 -2630365 -8608883 5813455 -4005459 -8844054 6703783
output:
impossible
result:
ok single line: 'impossible'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
14 6 13 3 7 2 13 6 8 4 5 12 13 3 10 4 11 2 14 3 4 5 13 10 14 10 14 3 12 -8599727 -1496394 855072 -7439122 -5170228 8009298 -250221 5841035 2949765 7166358 -3516548 -6851737 8173765 -917122
output:
impossible
result:
ok single line: 'impossible'
Test #11:
score: 0
Accepted
time: 382ms
memory: 106880kb
input:
60 21 34 13 34 48 49 31 42 5 6 16 30 1 25 35 37 3 14 3 32 25 54 2 41 24 44 27 52 26 55 8 35 31 47 41 42 4 35 53 59 13 19 11 51 36 48 5 59 40 44 28 50 5 51 37 53 50 60 14 50 22 58 20 50 20 21 5 20 19 55 5 45 19 35 7 29 5 53 25 33 19 51 37 41 13 29 12 24 13 40 10 22 1 5 22 32 14 42 11 41 16 60 35 43 3...
output:
impossible
result:
ok single line: 'impossible'
Test #12:
score: 0
Accepted
time: 391ms
memory: 106080kb
input:
60 4 11 1 7 8 24 2 18 11 26 6 18 5 26 5 11 6 21 17 30 9 22 1 29 7 14 9 18 23 26 3 28 3 14 4 16 7 18 2 3 8 8 10 20 8 29 5 28 5 7 16 19 16 18 8 11 5 28 12 21 8 20 8 27 9 23 15 28 1 4 6 27 10 15 10 20 2 7 4 21 9 23 23 25 20 23 19 29 16 25 12 15 3 27 3 9 1 26 9 11 12 14 14 24 16 22 7 7 9 26 24 29 3 27 1...
output:
impossible
result:
ok single line: 'impossible'
Test #13:
score: 0
Accepted
time: 358ms
memory: 105820kb
input:
60 2 4 15 18 1 17 3 10 11 19 3 14 14 14 9 10 9 15 1 17 10 17 3 9 4 10 6 10 7 14 3 20 20 20 5 14 1 9 3 17 10 14 3 13 8 15 9 13 5 9 2 16 4 9 9 19 13 18 4 20 8 19 13 18 9 11 11 14 8 17 7 11 1 11 5 7 10 12 3 8 8 18 9 20 11 19 1 16 1 17 3 20 3 3 2 10 7 7 4 18 8 16 5 7 16 20 1 5 10 15 9 11 2 6 11 19 6 16 ...
output:
impossible
result:
ok single line: 'impossible'
Test #14:
score: 0
Accepted
time: 215ms
memory: 105284kb
input:
60 1 3 1 3 3 5 2 6 5 5 2 5 5 6 1 5 3 6 6 6 2 6 2 2 2 3 1 6 2 4 2 3 1 3 4 5 2 4 5 5 3 5 3 5 1 5 2 6 3 6 1 6 1 4 3 3 2 2 1 6 2 3 2 6 4 6 5 5 1 6 2 3 1 2 4 4 2 5 1 4 4 4 4 6 2 6 2 3 2 4 1 2 1 4 3 6 2 5 2 6 1 1 1 5 5 6 3 6 1 2 3 5 5 6 5 6 1 6 3 4 -9765941 -9284625 -9136963 -1872925 -9334679 -67293 96416...
output:
-87758107
result:
ok single line: '-87758107'
Test #15:
score: 0
Accepted
time: 214ms
memory: 105412kb
input:
60 1 1 1 4 2 2 3 4 1 2 1 2 1 4 2 3 1 4 1 2 4 4 1 3 2 4 2 2 2 3 2 4 1 4 3 4 1 2 3 3 2 3 1 1 2 4 2 4 2 4 1 2 1 2 3 3 3 4 2 3 1 3 2 4 1 2 1 3 1 2 3 4 2 2 2 4 1 3 1 1 2 4 2 3 2 3 4 4 1 2 1 4 1 2 2 4 2 3 4 4 2 4 3 4 3 4 1 1 2 3 3 4 2 4 2 3 3 4 2 2 -8959736 5094365 2567070 -9106790 9323252 -7495337 818129...
output:
67209846
result:
ok single line: '67209846'
Test #16:
score: 0
Accepted
time: 194ms
memory: 106316kb
input:
60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 ...
output:
154133500
result:
ok single line: '154133500'
Test #17:
score: 0
Accepted
time: 216ms
memory: 106996kb
input:
60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 ...
output:
281129340
result:
ok single line: '281129340'
Test #18:
score: 0
Accepted
time: 242ms
memory: 105276kb
input:
60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 ...
output:
191361510
result:
ok single line: '191361510'
Test #19:
score: 0
Accepted
time: 174ms
memory: 106748kb
input:
60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 ...
output:
-1693012
result:
ok single line: '-1693012'
Test #20:
score: 0
Accepted
time: 178ms
memory: 105552kb
input:
60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 ...
output:
-354498
result:
ok single line: '-354498'
Test #21:
score: 0
Accepted
time: 244ms
memory: 106196kb
input:
60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 ...
output:
178078620
result:
ok single line: '178078620'
Test #22:
score: 0
Accepted
time: 231ms
memory: 106300kb
input:
60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 60 1 ...
output:
267872880
result:
ok single line: '267872880'
Test #23:
score: 0
Accepted
time: 665ms
memory: 106096kb
input:
60 1 60 2 55 5 60 5 55 3 58 1 57 5 57 3 57 2 55 4 55 3 57 1 57 1 56 3 60 5 57 1 55 4 60 2 60 3 58 1 55 5 56 2 60 2 59 2 58 4 59 5 59 4 58 4 58 2 56 2 59 4 55 4 56 3 60 5 57 4 56 3 56 4 57 2 55 1 55 1 56 2 58 4 59 5 56 1 57 3 55 1 55 2 59 3 56 2 58 5 55 5 57 5 58 5 58 4 58 5 58 2 60 1 59 1 55 3 58 1 ...
output:
101249576
result:
ok single line: '101249576'
Test #24:
score: -100
Time Limit Exceeded
input:
60 4 57 2 57 3 56 5 52 2 59 9 50 4 60 7 52 3 57 4 56 7 59 1 52 8 59 7 53 1 50 4 56 9 52 6 54 5 53 3 55 7 52 2 56 4 57 1 54 2 51 8 58 7 50 8 52 4 53 4 50 3 52 2 51 7 58 9 59 2 54 3 56 8 53 8 59 1 55 4 58 4 56 5 50 4 57 3 50 3 56 3 59 2 50 10 52 10 53 8 60 8 50 4 51 6 55 3 54 3 51 10 53 1 58 6 54 8 54...