# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
559170 |
2022-05-09T12:58:27 Z |
acm |
Road Closures (APIO21_roads) |
C++14 |
|
2000 ms |
25856 KB |
#include <bits/stdc++.h>
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define REP(i, l, r) for (int i = (l); i < (r); ++i)
#define FORD(i, r, l) for (int i = (r); i >= (l); --i)
#define REPD(i, r, l) for (int i = (r)-1; i >= (l); --i)
#define pb(x) push_back(x)
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1e5 + 5, Ns4 = 200005;
int n;
long long ans[N];
long long dpx[N], val[N];
int sz[Ns4];
long long dd[Ns4][2];
vector<pii> S[N];
void DFS(int u, int p, int max_sz) {
int now_sz = min(sz[u], max_sz), w = 0;
vector<int> Q;
long long sum = 0, pre_sum = 0;
for (auto [c, v] : S[u])
if (v != p) {
DFS(v, u, max_sz);
long long xx = dd[v][1] + c;
long long yy = dd[v][0];
sum += xx;
if (yy - xx < 0)
Q.push_back(yy - xx);
else
w++;
}
for (int i = 0; i <= min(w, 1); i++) Q.pb(0);
now_sz = min(now_sz, (int)Q.size());
pre_sum = 1e15;
if (now_sz && Q.size() > 1000) {
nth_element(Q.begin(), Q.begin() + now_sz - 1, Q.end());
int alta = Q[now_sz - 1];
int x = now_sz;
for (auto X : Q) {
if (X < alta) {
x--;
pre_sum = sum;
sum += min(0, X);
}
}
for (auto X : Q) {
if (X == alta && x) {
x--;
pre_sum = sum;
sum += min(0, X);
}
}
Q.clear();
} else {
sort(Q.begin(), Q.end());
pre_sum = 1e15;
REP(i, 0, now_sz) {
pre_sum = sum;
sum += min(0, Q[i]);
}
Q.clear();
}
if (now_sz < max_sz) pre_sum = sum;
dd[u][0] = pre_sum;
dd[u][1] = sum;
}
void calc(int i) {
DFS(0, 0, i);
ans[i] = dd[0][1];
}
void dnc(int l = 1, int r = n - 2, ll L = ans[n - 1], ll R = ans[0]) {
if (l > r) return;
if (L == R) {
for (int i = l; i <= r; i++) ans[i] = L;
return;
}
int tm = (l + r) / 2;
calc(tm);
dnc(l, tm - 1, ans[tm], R);
dnc(tm + 1, r, L, ans[tm]);
}
void sub34() {
REP(i, 0, n) {
sz[i] = S[i].size() - 1;
if (i == 0) ++sz[i];
}
calc(0);
calc(n - 1);
if (1 <= n - 2) dnc();
}
vector<long long> minimum_closure_costs(int N, vector<int> U, vector<int> V,
vector<int> W) {
n = N;
REP(i, 0, n - 1) {
S[U[i]].emplace_back(W[i], V[i]);
S[V[i]].emplace_back(W[i], U[i]);
}
sub34();
vector<long long> ret(n);
REP(i, 0, n) ret[i] = ans[i];
return ret;
}
Compilation message
roads.cpp: In function 'void DFS(int, int, int)':
roads.cpp:22:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
22 | for (auto [c, v] : S[u])
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
148 ms |
2848 KB |
Output is correct |
3 |
Correct |
164 ms |
2852 KB |
Output is correct |
4 |
Correct |
149 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2656 KB |
Output is correct |
6 |
Correct |
4 ms |
2644 KB |
Output is correct |
7 |
Correct |
4 ms |
2644 KB |
Output is correct |
8 |
Correct |
115 ms |
2824 KB |
Output is correct |
9 |
Correct |
167 ms |
2772 KB |
Output is correct |
10 |
Correct |
3 ms |
2644 KB |
Output is correct |
11 |
Correct |
3 ms |
2644 KB |
Output is correct |
12 |
Execution timed out |
2082 ms |
8312 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
172 ms |
21820 KB |
Output is correct |
3 |
Correct |
197 ms |
24256 KB |
Output is correct |
4 |
Correct |
218 ms |
25636 KB |
Output is correct |
5 |
Correct |
233 ms |
25856 KB |
Output is correct |
6 |
Correct |
4 ms |
3028 KB |
Output is correct |
7 |
Correct |
4 ms |
3028 KB |
Output is correct |
8 |
Correct |
4 ms |
3028 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
123 ms |
16460 KB |
Output is correct |
13 |
Correct |
208 ms |
25728 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
192 ms |
23432 KB |
Output is correct |
16 |
Correct |
223 ms |
25640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
4 ms |
2644 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2644 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
4 ms |
2644 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2644 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
4 ms |
2772 KB |
Output is correct |
24 |
Correct |
6 ms |
2772 KB |
Output is correct |
25 |
Correct |
5 ms |
2840 KB |
Output is correct |
26 |
Correct |
11 ms |
2772 KB |
Output is correct |
27 |
Correct |
49 ms |
2868 KB |
Output is correct |
28 |
Correct |
31 ms |
2868 KB |
Output is correct |
29 |
Correct |
6 ms |
2772 KB |
Output is correct |
30 |
Correct |
11 ms |
2868 KB |
Output is correct |
31 |
Correct |
12 ms |
2884 KB |
Output is correct |
32 |
Correct |
89 ms |
2864 KB |
Output is correct |
33 |
Correct |
4 ms |
3028 KB |
Output is correct |
34 |
Correct |
4 ms |
3116 KB |
Output is correct |
35 |
Correct |
4 ms |
3028 KB |
Output is correct |
36 |
Correct |
151 ms |
2848 KB |
Output is correct |
37 |
Correct |
161 ms |
2896 KB |
Output is correct |
38 |
Correct |
159 ms |
2892 KB |
Output is correct |
39 |
Correct |
2 ms |
2644 KB |
Output is correct |
40 |
Correct |
1 ms |
2644 KB |
Output is correct |
41 |
Correct |
2 ms |
2644 KB |
Output is correct |
42 |
Correct |
2 ms |
2644 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
2 ms |
2644 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
4 ms |
2700 KB |
Output is correct |
52 |
Correct |
3 ms |
2644 KB |
Output is correct |
53 |
Correct |
4 ms |
2772 KB |
Output is correct |
54 |
Correct |
5 ms |
2772 KB |
Output is correct |
55 |
Correct |
38 ms |
2872 KB |
Output is correct |
56 |
Correct |
114 ms |
2824 KB |
Output is correct |
57 |
Correct |
163 ms |
2848 KB |
Output is correct |
58 |
Correct |
2 ms |
2644 KB |
Output is correct |
59 |
Correct |
2 ms |
2644 KB |
Output is correct |
60 |
Correct |
3 ms |
2644 KB |
Output is correct |
61 |
Correct |
3 ms |
2644 KB |
Output is correct |
62 |
Correct |
4 ms |
2644 KB |
Output is correct |
63 |
Correct |
2 ms |
2644 KB |
Output is correct |
64 |
Correct |
5 ms |
2856 KB |
Output is correct |
65 |
Correct |
5 ms |
2856 KB |
Output is correct |
66 |
Correct |
10 ms |
2864 KB |
Output is correct |
67 |
Correct |
92 ms |
2844 KB |
Output is correct |
68 |
Correct |
8 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
11932 KB |
Output is correct |
2 |
Correct |
558 ms |
11784 KB |
Output is correct |
3 |
Execution timed out |
2079 ms |
11644 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
11932 KB |
Output is correct |
2 |
Correct |
558 ms |
11784 KB |
Output is correct |
3 |
Execution timed out |
2079 ms |
11644 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
148 ms |
2848 KB |
Output is correct |
3 |
Correct |
164 ms |
2852 KB |
Output is correct |
4 |
Correct |
149 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2656 KB |
Output is correct |
6 |
Correct |
4 ms |
2644 KB |
Output is correct |
7 |
Correct |
4 ms |
2644 KB |
Output is correct |
8 |
Correct |
115 ms |
2824 KB |
Output is correct |
9 |
Correct |
167 ms |
2772 KB |
Output is correct |
10 |
Correct |
3 ms |
2644 KB |
Output is correct |
11 |
Correct |
3 ms |
2644 KB |
Output is correct |
12 |
Execution timed out |
2082 ms |
8312 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |